@luma.gl/engine 9.3.0-alpha.4 → 9.3.0-alpha.8
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-loop/animation-loop.d.ts +8 -4
- package/dist/animation-loop/animation-loop.d.ts.map +1 -1
- package/dist/animation-loop/animation-loop.js +73 -43
- package/dist/animation-loop/animation-loop.js.map +1 -1
- package/dist/animation-loop/make-animation-loop.js +7 -1
- package/dist/animation-loop/make-animation-loop.js.map +1 -1
- package/dist/animation-loop/request-animation-frame.d.ts.map +1 -1
- package/dist/animation-loop/request-animation-frame.js +23 -6
- package/dist/animation-loop/request-animation-frame.js.map +1 -1
- package/dist/compute/computation.d.ts +3 -7
- package/dist/compute/computation.d.ts.map +1 -1
- package/dist/compute/computation.js +14 -12
- package/dist/compute/computation.js.map +1 -1
- package/dist/dist.dev.js +2310 -1638
- package/dist/dist.min.js +307 -360
- package/dist/dynamic-texture/dynamic-texture.d.ts +12 -5
- package/dist/dynamic-texture/dynamic-texture.d.ts.map +1 -1
- package/dist/dynamic-texture/dynamic-texture.js +222 -55
- package/dist/dynamic-texture/dynamic-texture.js.map +1 -1
- package/dist/dynamic-texture/texture-data.d.ts +8 -1
- package/dist/dynamic-texture/texture-data.d.ts.map +1 -1
- package/dist/dynamic-texture/texture-data.js +27 -2
- package/dist/dynamic-texture/texture-data.js.map +1 -1
- package/dist/geometries/cone-geometry.d.ts +3 -1
- package/dist/geometries/cone-geometry.d.ts.map +1 -1
- package/dist/geometries/cone-geometry.js.map +1 -1
- package/dist/geometries/cylinder-geometry.d.ts +2 -1
- package/dist/geometries/cylinder-geometry.d.ts.map +1 -1
- package/dist/geometries/cylinder-geometry.js.map +1 -1
- package/dist/geometry/gpu-geometry.d.ts.map +1 -1
- package/dist/geometry/gpu-geometry.js +8 -3
- package/dist/geometry/gpu-geometry.js.map +1 -1
- package/dist/index.cjs +2897 -2272
- package/dist/index.cjs.map +4 -4
- package/dist/index.d.ts +12 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -3
- package/dist/index.js.map +1 -1
- package/dist/material/material-factory.d.ts +73 -0
- package/dist/material/material-factory.d.ts.map +1 -0
- package/dist/material/material-factory.js +111 -0
- package/dist/material/material-factory.js.map +1 -0
- package/dist/material/material.d.ts +84 -0
- package/dist/material/material.d.ts.map +1 -0
- package/dist/material/material.js +176 -0
- package/dist/material/material.js.map +1 -0
- package/dist/model/model.d.ts +17 -7
- package/dist/model/model.d.ts.map +1 -1
- package/dist/model/model.js +80 -34
- package/dist/model/model.js.map +1 -1
- package/dist/model/split-uniforms-and-bindings.d.ts +4 -3
- package/dist/model/split-uniforms-and-bindings.d.ts.map +1 -1
- package/dist/model/split-uniforms-and-bindings.js +2 -2
- package/dist/model/split-uniforms-and-bindings.js.map +1 -1
- package/dist/models/billboard-texture-model.d.ts.map +1 -1
- package/dist/models/billboard-texture-model.js +10 -8
- package/dist/models/billboard-texture-model.js.map +1 -1
- package/dist/models/clip-space.js +7 -7
- package/dist/models/directional-light-model.d.ts +7 -0
- package/dist/models/directional-light-model.d.ts.map +1 -0
- package/dist/models/directional-light-model.js +23 -0
- package/dist/models/directional-light-model.js.map +1 -0
- package/dist/models/light-model-utils.d.ts +69 -0
- package/dist/models/light-model-utils.d.ts.map +1 -0
- package/dist/models/light-model-utils.js +395 -0
- package/dist/models/light-model-utils.js.map +1 -0
- package/dist/models/point-light-model.d.ts +7 -0
- package/dist/models/point-light-model.d.ts.map +1 -0
- package/dist/models/point-light-model.js +22 -0
- package/dist/models/point-light-model.js.map +1 -0
- package/dist/models/spot-light-model.d.ts +7 -0
- package/dist/models/spot-light-model.d.ts.map +1 -0
- package/dist/models/spot-light-model.js +23 -0
- package/dist/models/spot-light-model.js.map +1 -0
- package/dist/modules/picking/color-picking.d.ts +5 -9
- package/dist/modules/picking/color-picking.d.ts.map +1 -1
- package/dist/modules/picking/color-picking.js +122 -115
- package/dist/modules/picking/color-picking.js.map +1 -1
- package/dist/modules/picking/index-picking.d.ts +2 -2
- package/dist/modules/picking/index-picking.d.ts.map +1 -1
- package/dist/modules/picking/index-picking.js +36 -16
- package/dist/modules/picking/index-picking.js.map +1 -1
- package/dist/modules/picking/legacy-color-picking.d.ts +26 -0
- package/dist/modules/picking/legacy-color-picking.d.ts.map +1 -0
- package/dist/modules/picking/legacy-color-picking.js +7 -0
- package/dist/modules/picking/legacy-color-picking.js.map +1 -0
- package/dist/modules/picking/picking-manager.d.ts +29 -3
- package/dist/modules/picking/picking-manager.d.ts.map +1 -1
- package/dist/modules/picking/picking-manager.js +188 -41
- package/dist/modules/picking/picking-manager.js.map +1 -1
- package/dist/modules/picking/picking-uniforms.d.ts +12 -11
- package/dist/modules/picking/picking-uniforms.d.ts.map +1 -1
- package/dist/modules/picking/picking-uniforms.js +26 -13
- package/dist/modules/picking/picking-uniforms.js.map +1 -1
- package/dist/modules/picking/picking.d.ts +25 -0
- package/dist/modules/picking/picking.d.ts.map +1 -0
- package/dist/modules/picking/picking.js +18 -0
- package/dist/modules/picking/picking.js.map +1 -0
- package/dist/passes/get-fragment-shader.js +11 -30
- package/dist/passes/get-fragment-shader.js.map +1 -1
- package/dist/passes/shader-pass-renderer.d.ts +0 -2
- package/dist/passes/shader-pass-renderer.d.ts.map +1 -1
- package/dist/passes/shader-pass-renderer.js +4 -31
- package/dist/passes/shader-pass-renderer.js.map +1 -1
- package/dist/scenegraph/group-node.d.ts +5 -0
- package/dist/scenegraph/group-node.d.ts.map +1 -1
- package/dist/scenegraph/group-node.js +12 -0
- package/dist/scenegraph/group-node.js.map +1 -1
- package/dist/scenegraph/model-node.d.ts +2 -2
- package/dist/scenegraph/model-node.d.ts.map +1 -1
- package/dist/scenegraph/model-node.js.map +1 -1
- package/dist/scenegraph/scenegraph-node.d.ts +1 -1
- package/dist/scenegraph/scenegraph-node.d.ts.map +1 -1
- package/dist/scenegraph/scenegraph-node.js +23 -15
- package/dist/scenegraph/scenegraph-node.js.map +1 -1
- package/dist/shader-inputs.d.ts +9 -7
- package/dist/shader-inputs.d.ts.map +1 -1
- package/dist/shader-inputs.js +84 -4
- package/dist/shader-inputs.js.map +1 -1
- package/dist/utils/shader-module-utils.d.ts +7 -0
- package/dist/utils/shader-module-utils.d.ts.map +1 -0
- package/dist/utils/shader-module-utils.js +46 -0
- package/dist/utils/shader-module-utils.js.map +1 -0
- package/package.json +4 -4
- package/src/animation-loop/animation-loop.ts +78 -46
- package/src/animation-loop/make-animation-loop.ts +13 -5
- package/src/animation-loop/request-animation-frame.ts +32 -6
- package/src/compute/computation.ts +31 -17
- package/src/dynamic-texture/dynamic-texture.ts +301 -68
- package/src/dynamic-texture/texture-data.ts +39 -4
- package/src/geometries/cone-geometry.ts +6 -1
- package/src/geometries/cylinder-geometry.ts +5 -1
- package/src/geometry/gpu-geometry.ts +8 -3
- package/src/index.ts +29 -4
- package/src/material/material-factory.ts +157 -0
- package/src/material/material.ts +254 -0
- package/src/model/model.ts +122 -50
- package/src/model/split-uniforms-and-bindings.ts +8 -6
- package/src/models/billboard-texture-model.ts +10 -8
- package/src/models/clip-space.ts +7 -7
- package/src/models/directional-light-model.ts +32 -0
- package/src/models/light-model-utils.ts +587 -0
- package/src/models/point-light-model.ts +31 -0
- package/src/models/spot-light-model.ts +32 -0
- package/src/modules/picking/color-picking.ts +123 -122
- package/src/modules/picking/index-picking.ts +36 -16
- package/src/modules/picking/legacy-color-picking.ts +8 -0
- package/src/modules/picking/picking-manager.ts +252 -50
- package/src/modules/picking/picking-uniforms.ts +38 -23
- package/src/modules/picking/picking.ts +22 -0
- package/src/passes/get-fragment-shader.ts +11 -30
- package/src/passes/shader-pass-renderer.ts +4 -33
- package/src/scenegraph/group-node.ts +16 -0
- package/src/scenegraph/model-node.ts +2 -2
- package/src/scenegraph/scenegraph-node.ts +27 -16
- package/src/shader-inputs.ts +165 -15
- package/src/utils/shader-module-utils.ts +65 -0
- package/dist/dynamic-texture/mipmaps.d.ts +0 -6
- package/dist/dynamic-texture/mipmaps.d.ts.map +0 -1
- package/dist/dynamic-texture/mipmaps.js +0 -441
- package/dist/dynamic-texture/mipmaps.js.map +0 -1
- package/dist/factories/pipeline-factory.d.ts +0 -37
- package/dist/factories/pipeline-factory.d.ts.map +0 -1
- package/dist/factories/pipeline-factory.js +0 -181
- package/dist/factories/pipeline-factory.js.map +0 -1
- package/dist/factories/shader-factory.d.ts +0 -22
- package/dist/factories/shader-factory.d.ts.map +0 -1
- package/dist/factories/shader-factory.js +0 -89
- package/dist/factories/shader-factory.js.map +0 -1
- package/dist/types.d.ts +0 -7
- package/dist/types.d.ts.map +0 -1
- package/dist/types.js +0 -5
- package/dist/types.js.map +0 -1
- package/src/dynamic-texture/mipmaps.ts +0 -517
- package/src/factories/pipeline-factory.ts +0 -225
- package/src/factories/shader-factory.ts +0 -105
- package/src/types.ts +0 -11
package/dist/dist.min.js
CHANGED
|
@@ -4,169 +4,10 @@
|
|
|
4
4
|
else if (typeof define === 'function' && define.amd) define([], factory);
|
|
5
5
|
else if (typeof exports === 'object') exports['luma'] = factory();
|
|
6
6
|
else root['luma'] = factory();})(globalThis, function () {
|
|
7
|
-
"use strict";var __exports__=(()=>{var hs=Object.create;var Ct=Object.defineProperty;var ls=Object.getOwnPropertyDescriptor;var us=Object.getOwnPropertyNames;var ds=Object.getPrototypeOf,fs=Object.prototype.hasOwnProperty;var ps=(i,t,e)=>t in i?Ct(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var Ve=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),ms=(i,t)=>{for(var e in t)Ct(i,e,{get:t[e],enumerable:!0})},Ut=(i,t,e,s)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of us(t))!fs.call(i,r)&&r!==e&&Ct(i,r,{get:()=>t[r],enumerable:!(s=ls(t,r))||s.enumerable});return i},Vt=(i,t,e)=>(Ut(i,t,"default"),e&&Ut(e,t,"default")),O=(i,t,e)=>(e=i!=null?hs(ds(i)):{},Ut(t||!i||!i.__esModule?Ct(e,"default",{value:i,enumerable:!0}):e,i)),gs=i=>Ut(Ct({},"__esModule",{value:!0}),i);var B=(i,t,e)=>(ps(i,typeof t!="symbol"?t+"":t,e),e);var z=Ve((Vr,je)=>{je.exports=globalThis.luma});var ht=Ve((hn,Ye)=>{Ye.exports=globalThis.luma});var Nt={};ms(Nt,{AnimationLoop:()=>ct,AnimationLoopTemplate:()=>Wt,AsyncTexture:()=>Br,BackgroundTextureModel:()=>bt,BufferTransform:()=>kt,ClipSpace:()=>it,Computation:()=>ut,ConeGeometry:()=>ce,CubeGeometry:()=>he,CylinderGeometry:()=>le,DynamicTexture:()=>Y,GPUGeometry:()=>mt,Geometry:()=>V,GroupNode:()=>wt,IcoSphereGeometry:()=>ue,KeyFrames:()=>Gt,LegacyPickingManager:()=>ye,Model:()=>q,ModelNode:()=>ae,PickingManager:()=>Dt,PipelineFactory:()=>tt,PlaneGeometry:()=>de,ScenegraphNode:()=>rt,ShaderFactory:()=>et,ShaderInputs:()=>Z,ShaderPassRenderer:()=>me,SphereGeometry:()=>fe,Swap:()=>At,SwapBuffers:()=>pe,SwapFramebuffers:()=>St,TextureTransform:()=>Qt,Timeline:()=>jt,TruncatedConeGeometry:()=>ot,cancelAnimationFramePolyfill:()=>Yt,colorPicking:()=>rs,indexPicking:()=>ss,loadImage:()=>ts,loadImageBitmap:()=>Ji,makeAnimationLoop:()=>qe,makeRandomGenerator:()=>Zi,requestAnimationFramePolyfill:()=>qt,setPathPrefix:()=>Qi});Vt(Nt,O(z(),1));var xs=1,ys=1,jt=class{time=0;channels=new Map;animations=new Map;playing=!1;lastEngineTime=-1;constructor(){}addChannel(t){let{delay:e=0,duration:s=Number.POSITIVE_INFINITY,rate:r=1,repeat:n=1}=t,o=xs++,a={time:0,delay:e,duration:s,rate:r,repeat:n};return this._setChannelTime(a,this.time),this.channels.set(o,a),o}removeChannel(t){this.channels.delete(t);for(let[e,s]of this.animations)s.channel===t&&this.detachAnimation(e)}isFinished(t){let e=this.channels.get(t);return e===void 0?!1:this.time>=e.delay+e.duration*e.repeat}getTime(t){if(t===void 0)return this.time;let e=this.channels.get(t);return e===void 0?-1:e.time}setTime(t){this.time=Math.max(0,t);let e=this.channels.values();for(let r of e)this._setChannelTime(r,this.time);let s=this.animations.values();for(let r of s){let{animation:n,channel:o}=r;n.setTime(this.getTime(o))}}play(){this.playing=!0}pause(){this.playing=!1,this.lastEngineTime=-1}reset(){this.setTime(0)}attachAnimation(t,e){let s=ys++;return this.animations.set(s,{animation:t,channel:e}),t.setTime(this.getTime(e)),s}detachAnimation(t){this.animations.delete(t)}update(t){this.playing&&(this.lastEngineTime===-1&&(this.lastEngineTime=t),this.setTime(this.time+(t-this.lastEngineTime)),this.lastEngineTime=t)}_setChannelTime(t,e){let s=e-t.delay,r=t.duration*t.repeat;s>=r?t.time=t.duration*t.rate:(t.time=Math.max(0,s)%t.duration,t.time*=t.rate)}};var Gt=class{startIndex=-1;endIndex=-1;factor=0;times=[];values=[];_lastTime=-1;constructor(t){this.setKeyFrames(t),this.setTime(0)}setKeyFrames(t){let e=t.length;this.times.length=e,this.values.length=e;for(let s=0;s<e;++s)this.times[s]=t[s][0],this.values[s]=t[s][1];this._calculateKeys(this._lastTime)}setTime(t){t=Math.max(0,t),t!==this._lastTime&&(this._calculateKeys(t),this._lastTime=t)}getStartTime(){return this.times[this.startIndex]}getEndTime(){return this.times[this.endIndex]}getStartData(){return this.values[this.startIndex]}getEndData(){return this.values[this.endIndex]}_calculateKeys(t){let e=0,s=this.times.length;for(e=0;e<s-2&&!(this.times[e+1]>t);++e);this.startIndex=e,this.endIndex=e+1;let r=this.times[this.startIndex],n=this.times[this.endIndex];this.factor=Math.min(Math.max(0,(t-r)/(n-r)),1)}};var Wt=class{constructor(t){}async onInitialize(t){return null}};var Ge=O(z(),1);function qt(i){return typeof window<"u"&&window.requestAnimationFrame?window.requestAnimationFrame(i):setTimeout(i,1e3/60)}function Yt(i){return typeof window<"u"&&window.cancelAnimationFrame?window.cancelAnimationFrame(i):clearTimeout(i)}function It(){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 at=class{constructor(t,e){this.sampleSize=1,this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this.name=t,this.type=e,this.reset()}reset(){return this.time=0,this.count=0,this.samples=0,this.lastTiming=0,this.lastSampleTime=0,this.lastSampleCount=0,this._count=0,this._time=0,this._samples=0,this._startTime=0,this._timerPending=!1,this}setSampleSize(t){return this.sampleSize=t,this}incrementCount(){return this.addCount(1),this}decrementCount(){return this.subtractCount(1),this}addCount(t){return this._count+=t,this._samples++,this._checkSampling(),this}subtractCount(t){return this._count-=t,this._samples++,this._checkSampling(),this}addTime(t){return this._time+=t,this.lastTiming=t,this._samples++,this._checkSampling(),this}timeStart(){return this._startTime=It(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(It()-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 pt=class{constructor(t){this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t,e="count"){return this._getOrCreate({name:t,type:e})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let e of Object.values(this.stats))t(e)}getTable(){let t={};return this.forEach(e=>{t[e.name]={time:e.time||0,count:e.count||0,average:e.getAverageTime()||0,hz:e.getHz()||0}}),t}_initializeStats(t=[]){t.forEach(e=>this._getOrCreate(e))}_getOrCreate(t){let{name:e,type:s}=t,r=this.stats[e];return r||(t instanceof at?r=t:r=new at(e,s),this.stats[e]=r),r}};var bs=0,be=class{device=null;canvas=null;props;animationProps=null;timeline=null;stats;cpuTime;gpuTime;frameRate;display;_needsRedraw="initialized";_initialized=!1;_running=!1;_animationFrameId=null;_nextFramePromise=null;_resolveNextFrame=null;_cpuStartTime=0;_error=null;constructor(t){if(this.props={...be.defaultAnimationLoopProps,...t},t=this.props,!t.device)throw new Error("No device provided");this.stats=t.stats||new pt({id:"animation-loop-stats"}),this.cpuTime=this.stats.get("CPU Time"),this.gpuTime=this.stats.get("GPU Time"),this.frameRate=this.stats.get("Frame Rate"),this.setProps({autoResizeViewport:t.autoResizeViewport}),this.start=this.start.bind(this),this.stop=this.stop.bind(this),this._onMousemove=this._onMousemove.bind(this),this._onMouseleave=this._onMouseleave.bind(this)}destroy(){this.stop(),this._setDisplay(null)}delete(){this.destroy()}reportError(t){this.props.onError(t),this._error=t}setNeedsRedraw(t){return this._needsRedraw=this._needsRedraw||t,this}needsRedraw(){let t=this._needsRedraw;return this._needsRedraw=!1,t}setProps(t){return"autoResizeViewport"in t&&(this.props.autoResizeViewport=t.autoResizeViewport||!1),this}async start(){if(this._running)return this;this._running=!0;try{let t;return this._initialized||(this._initialized=!0,await this._initDevice(),this._initialize(),await this.props.onInitialize(this._getAnimationProps())),this._running?(t!==!1&&(this._cancelAnimationFrame(),this._requestAnimationFrame()),this):null}catch(t){let e=t instanceof Error?t:new Error("Unknown error");throw this.props.onError(e),e}}stop(){return this._running&&(this.animationProps&&!this._error&&this.props.onFinalize(this.animationProps),this._cancelAnimationFrame(),this._nextFramePromise=null,this._resolveNextFrame=null,this._running=!1),this}redraw(){return this.device?.isLost||this._error?this:(this._beginFrameTimers(),this._setupFrame(),this._updateAnimationProps(),this._renderFrame(this._getAnimationProps()),this._clearNeedsRedraw(),this._resolveNextFrame&&(this._resolveNextFrame(this),this._nextFramePromise=null,this._resolveNextFrame=null),this._endFrameTimers(),this)}attachTimeline(t){return this.timeline=t,this.timeline}detachTimeline(){this.timeline=null}waitForRender(){return this.setNeedsRedraw("waitForRender"),this._nextFramePromise||(this._nextFramePromise=new Promise(t=>{this._resolveNextFrame=t})),this._nextFramePromise}async toDataURL(){if(this.setNeedsRedraw("toDataURL"),await this.waitForRender(),this.canvas instanceof HTMLCanvasElement)return this.canvas.toDataURL();throw new Error("OffscreenCanvas")}_initialize(){this._startEventHandling(),this._initializeAnimationProps(),this._updateAnimationProps(),this._resizeViewport()}_setDisplay(t){this.display&&(this.display.destroy(),this.display.animationLoop=null),t&&(t.animationLoop=this),this.display=t}_requestAnimationFrame(){this._running&&(this._animationFrameId=qt(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(Yt(this._animationFrameId),this._animationFrameId=null)}_animationFrame(){this._running&&(this.redraw(),this._requestAnimationFrame())}_renderFrame(t){if(this.display){this.display._renderFrame(t);return}this.props.onRender(this._getAnimationProps()),this.device?.submit()}_clearNeedsRedraw(){this._needsRedraw=!1}_setupFrame(){this._resizeViewport()}_initializeAnimationProps(){let t=this.device?.getDefaultCanvasContext();if(!this.device||!t)throw new Error("loop");let e=t?.canvas,s=t.props.useDevicePixels;this.animationProps={animationLoop:this,device:this.device,canvasContext:t,canvas:e,useDevicePixels:s,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:s}=this._getSizeAndAspect();(t!==this.animationProps.width||e!==this.animationProps.height)&&this.setNeedsRedraw("drawing buffer resized"),s!==this.animationProps.aspect&&this.setNeedsRedraw("drawing buffer aspect changed"),this.animationProps.width=t,this.animationProps.height=e,this.animationProps.aspect=s,this.animationProps.needsRedraw=this._needsRedraw,this.animationProps.engineTime=Date.now()-this.animationProps.startTime,this.timeline&&this.timeline.update(this.animationProps.engineTime),this.animationProps.tick=Math.floor(this.animationProps.time/1e3*60),this.animationProps.tock++,this.animationProps.time=this.timeline?this.timeline.getTime():this.animationProps.engineTime}async _initDevice(){if(this.device=await this.props.device,!this.device)throw new Error("No device provided");this.canvas=this.device.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 s=this.props.onAddHTML(e);s&&(e.innerHTML=s)}}_getSizeAndAspect(){if(!this.device)return{width:1,height:1,aspect:1};let[t,e]=this.device?.getDefaultCanvasContext().getDevicePixelSize()||[1,1],s=1,r=this.device?.getDefaultCanvasContext().canvas;return r&&r.clientHeight?s=r.clientWidth/r.clientHeight:t>0&&e>0&&(s=t/e),{width:t,height:e,aspect:s}}_resizeViewport(){this.props.autoResizeViewport&&this.device.gl&&this.device.gl.viewport(0,0,this.device.gl.drawingBufferWidth,this.device.gl.drawingBufferHeight)}_beginFrameTimers(){this.frameRate.timeEnd(),this.frameRate.timeStart(),this.cpuTime.timeStart()}_endFrameTimers(){this.cpuTime.timeEnd()}_startEventHandling(){this.canvas&&(this.canvas.addEventListener("mousemove",this._onMousemove.bind(this)),this.canvas.addEventListener("mouseleave",this._onMouseleave.bind(this)))}_onMousemove(t){t instanceof MouseEvent&&(this._getAnimationProps()._mousePosition=[t.offsetX,t.offsetY])}_onMouseleave(t){this._getAnimationProps()._mousePosition=null}},ct=be;B(ct,"defaultAnimationLoopProps",{device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:t=>console.error(t),stats:Ge.luma.stats.get(`animation-loop-${bs++}`),autoResizeViewport:!1});var We=O(z(),1);function qe(i,t){let e=null,s=t?.device||We.luma.createDevice({id:"animation-loop",adapters:t?.adapters,createCanvasContext:!0}),r=new ct({...t,device:s,async onInitialize(n){Ms(n.animationLoop.device);try{return e=new i(n),await e?.onInitialize(n)}catch(o){return vs(n.animationLoop.device,o),null}},onRender:n=>e?.onRender(n),onFinalize:n=>e?.onFinalize(n)});return r.getInfo=()=>this.AnimationLoopTemplateCtor.info,r}function vs(i,t){let e=i?.getDefaultCanvasContext().canvas;if(e instanceof HTMLCanvasElement){e.style.overflow="visible";let s=document.getElementById("animation-loop-error");s?.remove(),s=document.createElement("h1"),s.id="animation-loop-error",s.innerHTML=t.message,s.style.position="absolute",s.style.top="10px",s.style.left="10px",s.style.color="black",s.style.backgroundColor="red",e.parentElement?.appendChild(s)}}function Ms(i){let t=document.getElementById("animation-loop-error");t&&t.remove()}var T=O(z(),1),mi=O(ht(),1);var Pt=O(z(),1);var ve={};function I(i="id"){ve[i]=ve[i]||1;let t=ve[i]++;return`${i}-${t}`}var mt=class{id;userData={};topology;bufferLayout=[];vertexCount;indices;attributes;constructor(t){if(this.id=t.id||I("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&Pt.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 Xe(i,t){if(t instanceof mt)return t;let e=_s(i,t),{attributes:s,bufferLayout:r}=ws(i,t);return new mt({topology:t.topology||"triangle-list",bufferLayout:r,vertexCount:t.vertexCount,indices:e,attributes:s})}function _s(i,t){if(!t.indices)return;let e=t.indices.value;return i.createBuffer({usage:Pt.Buffer.INDEX,data:e})}function ws(i,t){let e=[],s={};for(let[n,o]of Object.entries(t.attributes)){let a=n;switch(n){case"POSITION":a="positions";break;case"NORMAL":a="normals";break;case"TEXCOORD_0":a="texCoords";break;case"COLOR_0":a="colors";break}if(o){s[a]=i.createBuffer({data:o.value,id:`${n}-buffer`});let{value:c,size:h,normalized:l}=o;e.push({name:a,format:(0,Pt.getVertexFormatFromAttribute)(c,h,l)})}}let r=t._calculateVertexCount(t.attributes,t.indices);return{attributes:s,bufferLayout:e,vertexCount:r}}var G=O(z(),1);var Me=class{static getDefaultPipelineFactory(t){let e=t.getModuleData("@luma.gl/engine");return e.defaultPipelineFactory||=new Me(t),e.defaultPipelineFactory}device;cachingEnabled;destroyPolicy;debug;_hashCounter=0;_hashes={};_renderPipelineCache={};_computePipelineCache={};get[Symbol.toStringTag](){return"PipelineFactory"}toString(){return`PipelineFactory(${this.device.id})`}constructor(t){this.device=t,this.cachingEnabled=t.props._cachePipelines,this.destroyPolicy=t.props._cacheDestroyPolicy,this.debug=t.props.debugFactories}createRenderPipeline(t){if(!this.cachingEnabled)return this.device.createRenderPipeline(t);let e={...G.RenderPipeline.defaultProps,...t},s=this._renderPipelineCache,r=this._hashRenderPipeline(e),n=s[r]?.pipeline;return n?(s[r].useCount++,this.debug&&G.log.log(3,`${this}: ${s[r].pipeline} reused, count=${s[r].useCount}, (id=${t.id})`)()):(n=this.device.createRenderPipeline({...e,id:e.id?`${e.id}-cached`:I("unnamed-cached")}),n.hash=r,s[r]={pipeline:n,useCount:1},this.debug&&G.log.log(3,`${this}: ${n} created, count=${s[r].useCount}`)()),n}createComputePipeline(t){if(!this.cachingEnabled)return this.device.createComputePipeline(t);let e={...G.ComputePipeline.defaultProps,...t},s=this._computePipelineCache,r=this._hashComputePipeline(e),n=s[r]?.pipeline;return n?(s[r].useCount++,this.debug&&G.log.log(3,`${this}: ${s[r].pipeline} reused, count=${s[r].useCount}, (id=${t.id})`)()):(n=this.device.createComputePipeline({...e,id:e.id?`${e.id}-cached`:void 0}),n.hash=r,s[r]={pipeline:n,useCount:1},this.debug&&G.log.log(3,`${this}: ${n} created, count=${s[r].useCount}`)()),n}release(t){if(!this.cachingEnabled){t.destroy();return}let e=this._getCache(t),s=t.hash;e[s].useCount--,e[s].useCount===0?(this._destroyPipeline(t),this.debug&&G.log.log(3,`${this}: ${t} released and destroyed`)()):e[s].useCount<0?(G.log.error(`${this}: ${t} released, useCount < 0, resetting`)(),e[s].useCount=0):this.debug&&G.log.log(3,`${this}: ${t} released, count=${e[s].useCount}`)()}_destroyPipeline(t){let e=this._getCache(t);switch(this.destroyPolicy){case"never":return!1;case"unused":return delete e[t.hash],t.destroy(),!0}}_getCache(t){let e;if(t instanceof G.ComputePipeline&&(e=this._computePipelineCache),t instanceof G.RenderPipeline&&(e=this._renderPipelineCache),!e)throw new Error(`${this}`);if(!e[t.hash])throw new Error(`${this}: ${t} matched incorrect entry`);return e}_hashComputePipeline(t){let{type:e}=this.device,s=this._getHash(t.shader.source);return`${e}/C/${s}`}_hashRenderPipeline(t){let e=t.vs?this._getHash(t.vs.source):0,s=t.fs?this._getHash(t.fs.source):0,r="-",n=this._getHash(JSON.stringify(t.bufferLayout)),{type:o}=this.device;switch(o){case"webgl":return`${o}/R/${e}/${s}V${r}BL${n}`;case"webgpu":default:let a=this._getHash(JSON.stringify(t.parameters));return`${o}/R/${e}/${s}V${r}T${t.topology}P${a}BL${n}`}}_getHash(t){return this._hashes[t]===void 0&&(this._hashes[t]=this._hashCounter++),this._hashes[t]}},tt=Me;B(tt,"defaultProps",{...G.RenderPipeline.defaultProps});var lt=O(z(),1);var _e=class{static getDefaultShaderFactory(t){let e=t.getModuleData("@luma.gl/engine");return e.defaultShaderFactory||=new _e(t),e.defaultShaderFactory}device;cachingEnabled;destroyPolicy;debug;_cache={};get[Symbol.toStringTag](){return"ShaderFactory"}toString(){return`${this[Symbol.toStringTag]}(${this.device.id})`}constructor(t){this.device=t,this.cachingEnabled=t.props._cacheShaders,this.destroyPolicy=t.props._cacheDestroyPolicy,this.debug=!0}createShader(t){if(!this.cachingEnabled)return this.device.createShader(t);let e=this._hashShader(t),s=this._cache[e];if(s)s.useCount++,this.debug&<.log.log(3,`${this}: Reusing shader ${s.shader.id} count=${s.useCount}`)();else{let r=this.device.createShader({...t,id:t.id?`${t.id}-cached`:void 0});this._cache[e]=s={shader:r,useCount:1},this.debug&<.log.log(3,`${this}: Created new shader ${r.id}`)()}return s.shader}release(t){if(!this.cachingEnabled){t.destroy();return}let e=this._hashShader(t),s=this._cache[e];if(s)if(s.useCount--,s.useCount===0)this.destroyPolicy==="unused"&&(delete this._cache[e],s.shader.destroy(),this.debug&<.log.log(3,`${this}: Releasing shader ${t.id}, destroyed`)());else{if(s.useCount<0)throw new Error(`ShaderFactory: Shader ${t.id} released too many times`);this.debug&<.log.log(3,`${this}: Releasing shader ${t.id} count=${s.useCount}`)()}}_hashShader(t){return`${t.stage}:${t.source}`}},et=_e;B(et,"defaultProps",{...lt.Shader.defaultProps});function He(i,t){let e={},s="Values";if(i.attributes.length===0&&!i.varyings?.length)return{"No attributes or varyings":{[s]:"N/A"}};for(let r of i.attributes)if(r){let n=`${r.location} ${r.name}: ${r.type}`;e[`in ${n}`]={[s]:r.stepMode||"vertex"}}for(let r of i.varyings||[]){let n=`${r.location} ${r.name}`;e[`out ${n}`]={[s]:JSON.stringify(r)}}return e}var D=null,we=null;function Ke(i,{id:t,minimap:e,opaque:s,top:r="0",left:n="0",rgbaScale:o=1}){D||(D=document.createElement("canvas"),D.id=t,D.title=t,D.style.zIndex="100",D.style.position="absolute",D.style.top=r,D.style.left=n,D.style.border="blue 5px solid",D.style.transform="scaleY(-1)",document.body.appendChild(D),we=D.getContext("2d")),(D.width!==i.width||D.height!==i.height)&&(D.width=i.width/2,D.height=i.height/2,D.style.width="400px",D.style.height="400px");let a=i.device.readPixelsToArrayWebGL(i),c=we?.createImageData(i.width,i.height);if(c){for(let l=0;l<a.length;l+=4)c.data[0+l+0]=a[l+0]*o,c.data[0+l+1]=a[l+1]*o,c.data[0+l+2]=a[l+2]*o,c.data[0+l+3]=s?255:a[l+3]*o;we?.putImageData(c,0,0)}}function Xt(i,t,e){if(i===t)return!0;if(!e||!i||!t)return!1;if(Array.isArray(i)){if(!Array.isArray(t)||i.length!==t.length)return!1;for(let s=0;s<i.length;s++)if(!Xt(i[s],t[s],e-1))return!1;return!0}if(Array.isArray(t))return!1;if(typeof i=="object"&&typeof t=="object"){let s=Object.keys(i),r=Object.keys(t);if(s.length!==r.length)return!1;for(let n of s)if(!t.hasOwnProperty(n)||!Xt(i[n],t[n],e-1))return!1;return!0}return!1}var Ze=O(z(),1),gt=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 s=[...t];for(let r of e){let n=s.findIndex(o=>o.name===r.name);n<0?s.push(r):s[n]=r}return s}getBufferIndex(t){let e=this.bufferLayouts.findIndex(s=>s.name===t);return e===-1&&Ze.log.warn(`BufferLayout: Missing buffer for "${t}".`)(),e}};function Qe(i,t){let e=1/0;for(let s of i){let r=t[s];r!==void 0&&(e=Math.min(e,r))}return e}function Je(i,t){let e=Object.fromEntries(i.attributes.map(r=>[r.name,r.location])),s=t.slice();return s.sort((r,n)=>{let o=r.attributes?r.attributes.map(l=>l.attribute):[r.name],a=n.attributes?n.attributes.map(l=>l.attribute):[n.name],c=Qe(o,e),h=Qe(a,e);return c-h}),s}var Ht=O(z(),1),si=O(ht(),1);function ti(i){return ArrayBuffer.isView(i)&&!(i instanceof DataView)}function ei(i){return Array.isArray(i)?i.length===0||typeof i[0]=="number":!1}function Et(i){return ti(i)||ei(i)}function As(i){return Et(i)||typeof i=="number"||typeof i=="boolean"}function ii(i){let t={bindings:{},uniforms:{}};return Object.keys(i).forEach(e=>{let s=i[e];As(s)?t.uniforms[e]=s:t.bindings[e]=s}),t}var Z=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;constructor(t,e){Object.assign(this.options,e);let s=(0,si.getShaderModuleDependencies)(Object.values(t).filter(r=>r.dependencies));for(let r of s)t[r.name]=r;Ht.log.log(1,"Creating ShaderInputs with modules",Object.keys(t))(),this.modules=t,this.moduleUniforms={},this.moduleBindings={};for(let[r,n]of Object.entries(t))this._addModule(n),n.name&&r!==n.name&&!this.options.disableWarnings&&Ht.log.warn(`Module name: ${r} vs ${n.name}`)()}destroy(){}setProps(t){for(let e of Object.keys(t)){let s=e,r=t[s]||{},n=this.modules[s];if(!n){this.options.disableWarnings||Ht.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[s],a=this.moduleBindings[s],c=n.getUniforms?.(r,o)||r,{uniforms:h,bindings:l}=ii(c);this.moduleUniforms[s]={...o,...h},this.moduleBindings[s]={...a,...l}}}getModules(){return Object.values(this.modules)}getUniformValues(){return this.moduleUniforms}getBindingValues(){let t={};for(let e of Object.values(this.moduleBindings))Object.assign(t,e);return t}getDebugTable(){let t={};for(let[e,s]of Object.entries(this.moduleUniforms))for(let[r,n]of Object.entries(s))t[`${e}.${r}`]={type:this.modules[e].uniformTypes?.[r],value:String(n)};return t}_addModule(t){let e=t.name;this.moduleUniforms[e]=t.defaultUniforms||{},this.moduleBindings[e]={}}};var N=O(z(),1);var Ot=O(z(),1);var Ae={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function Lt(i){return i?Array.isArray(i)?i[0]??null:i:null}function ri(i){let{dimension:t,data:e}=i;if(!e)return null;switch(t){case"1d":{let s=Lt(e);if(!s)return null;let{width:r}=Rt(s);return{width:r,height:1}}case"2d":{let s=Lt(e);return s?Rt(s):null}case"3d":case"2d-array":{if(!Array.isArray(e)||e.length===0)return null;let s=Lt(e[0]);return s?Rt(s):null}case"cube":{let s=Object.keys(e)[0]??null;if(!s)return null;let r=e[s],n=Lt(r);return n?Rt(n):null}case"cube-array":{if(!Array.isArray(e)||e.length===0)return null;let s=e[0],r=Object.keys(s)[0]??null;if(!r)return null;let n=Lt(s[r]);return n?Rt(n):null}default:return null}}function Rt(i){if((0,Ot.isExternalImage)(i))return(0,Ot.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 Ss(i){return typeof i=="object"&&i!==null&&"data"in i&&"width"in i&&"height"in i}function ni(i){let t=Ae[i];if(t===void 0)throw new Error(`Invalid cube face: ${i}`);return t}function Ts(i,t){return 6*i+ni(t)}function oi(i){throw new Error("setTexture1DData not supported in WebGL.")}function Cs(i){return Array.isArray(i)?i:[i]}function xt(i,t){let e=Cs(t),s=i,r=[];for(let n=0;n<e.length;n++){let o=e[n];if((0,Ot.isExternalImage)(o))r.push({type:"external-image",image:o,z:s,mipLevel:n});else if(Ss(o))r.push({type:"texture-data",data:o,z:s,mipLevel:n});else throw new Error("Unsupported 2D mip-level payload")}return r}function ai(i){let t=[];for(let e=0;e<i.length;e++)t.push(...xt(e,i[e]));return t}function ci(i){let t=[];for(let e=0;e<i.length;e++)t.push(...xt(e,i[e]));return t}function hi(i){let t=[];for(let[e,s]of Object.entries(i)){let r=ni(e);t.push(...xt(r,s))}return t}function li(i){let t=[];return i.forEach((e,s)=>{for(let[r,n]of Object.entries(e)){let o=Ts(s,r);t.push(...xt(o,n))}}),t}var dt=O(z(),1);var U=O(z(),1),ui=O(ht(),1);var Se=2,Is=1e4,Te=class{device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;source;shader;shaderInputs;_uniformStore;_pipelineNeedsUpdate="newly created";_getModuleUniforms;props;_destroyed=!1;constructor(t,e){if(t.type!=="webgpu")throw new Error("Computation is only supported in WebGPU");this.props={...Te.defaultProps,...e},e=this.props,this.id=e.id||I("model"),this.device=t,Object.assign(this.userData,e.userData);let s=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]);this.shaderInputs=e.shaderInputs||new Z(s),this.setShaderInputs(this.shaderInputs),this.props.shaderLayout||=t.getShaderLayout(this.props.source);let r=Ps(t),n=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];this.pipelineFactory=e.pipelineFactory||tt.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||et.getDefaultShaderFactory(this.device);let{source:o,getUniforms:a}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:r,...this.props,modules:n});this.source=o,this._getModuleUniforms=a,this.pipeline=this._updatePipeline(),e.bindings&&this.setBindings(e.bindings),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.shader),this._uniformStore.destroy(),this._destroyed=!0)}predraw(){this.updateShaderInputs()}dispatch(t,e,s,r){try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),t.setPipeline(this.pipeline),t.setBindings([]),t.dispatch(e,s,r)}finally{this._logDrawCallEnd()}}setVertexCount(t){}setInstanceCount(t){}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new U.UniformStore(this.shaderInputs.modules);for(let e of Object.keys(this.shaderInputs.modules)){let s=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=s}}setShaderModuleProps(t){let e=this._getModuleUniforms(t),s=Object.keys(e).filter(n=>{let o=e[n];return!Et(o)&&typeof o!="number"&&typeof o!="boolean"}),r={};for(let n of s)r[n]=e[n],delete e[n]}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues())}setBindings(t){Object.assign(this.bindings,t)}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate=this._pipelineNeedsUpdate||t}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null;this.pipeline&&(U.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.shader),this._pipelineNeedsUpdate=!1,this.shader=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"compute",source:this.source,debugShaders:this.props.debugShaders}),this.pipeline=this.pipelineFactory.createComputePipeline({...this.props,shader:this.shader}),t&&this.shaderFactory.release(t)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=U.log.level>3?0:Is;U.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,U.log.group(Se,`>>> DRAWING MODEL ${this.id}`,{collapsed:U.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=this.shaderInputs.getDebugTable();U.log.table(Se,t)(),U.log.groupEnd(Se)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(t,e){let s=(0,U.getTypedArrayConstructor)(e);return(t instanceof U.Buffer?new s(t.debugData):t).toString()}},ut=Te;B(ut,"defaultProps",{...U.ComputePipeline.defaultProps,id:"unnamed",handle:void 0,userData:{},source:"",modules:[],defines:{},bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:ui.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0});function Ps(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}var Es=["2d","2d-array","cube","cube-array"],yt={x:4,y:4,z:4};function di(i,t){if(!(t.mipLevels<=1)){if(i.type!=="webgpu")throw new Error(`Cannot generate mipmaps on device type "${i.type}". Use generateMipmapsWebGL for WebGL devices.`);if(t.dimension==="3d"){Rs(i,t);return}if(Es.includes(t.dimension)){Ls(i,t);return}throw new Error(`Cannot generate mipmaps for texture dimension "${t.dimension}" with WebGPU.`)}}function Ls(i,t){Kt(i,t,["render","filter"],"render");let e=fi(t.format,"render",t.dimension),s=t.dimension,r=ks(s),n=i.createSampler({minFilter:"linear",magFilter:"linear"}),o=new Uint32Array(1),a=i.createBuffer({byteLength:16,usage:dt.Buffer.UNIFORM|dt.Buffer.COPY_DST}),c=new q(i,{source:r,colorAttachmentFormats:[e],topology:"triangle-list",vertexCount:3,shaderLayout:{attributes:[],bindings:[{type:"sampler",name:"sourceSampler",group:0,location:0},{type:"texture",name:"sourceTexture",group:0,location:1,viewDimension:s,sampleType:"float"},{type:"uniform",name:"uniforms",group:0,location:2}]},bindings:{sourceSampler:n,sourceTexture:t,uniforms:a}}),h=t.width,l=t.height,u=t.dimension==="2d"?1:t.depth;try{for(let d=1;d<t.mipLevels;++d){Kt(i,t,["render","filter"],"render");let m=d-1,x=Math.max(1,h>>1),f=Math.max(1,l>>1),y=t.createView({dimension:s,baseMipLevel:m,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:t.depth});c.setBindings({sourceTexture:y});for(let b=0;b<u;++b){o[0]=b,a.write(o);let _=t.createView({dimension:"2d",baseMipLevel:d,mipLevelCount:1,baseArrayLayer:b,arrayLayerCount:1}),p=i.createFramebuffer({colorAttachments:[_]}),g=i.beginRenderPass({id:`mipmap-generation:${t.format}:${d}:${b}`,framebuffer:p});g.setParameters({viewport:[0,0,x,f,0,1],scissorRect:[0,0,x,f]}),c.draw(g),g.end(),i.submit(),_.destroy(),p.destroy()}y.destroy(),h=x,l=f}}finally{c.destroy(),n.destroy(),a.destroy()}}function fi(i,t,e){if(dt.textureFormatDecoder.isColor(i))return i;throw new Error(`Cannot run ${t} mipmap generation for ${e} texture with format "${i}". Only color textures can be used for this operation. Required capabilities: color. Actual capabilities: color=false.`)}function Rs(i,t){Kt(i,t,["filter","store"],"compute");let e=fi(t.format,"compute",t.dimension),s=Ns(e),r=i.createBuffer({byteLength:32,usage:dt.Buffer.UNIFORM|dt.Buffer.COPY_DST}),n=new Uint32Array(8),o=t.width,a=t.height,c=t.depth;try{for(let h=1;h<t.mipLevels;++h){Kt(i,t,["filter","store"],"compute");let l=Math.max(1,o>>1),u=Math.max(1,a>>1),d=Math.max(1,c>>1);n[0]=o,n[1]=a,n[2]=c,n[3]=l,n[4]=u,n[5]=d,n[6]=0,r.write(n);let m=t.createView({dimension:"3d",baseMipLevel:h-1,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1}),x=t.createView({dimension:"3d",baseMipLevel:h,mipLevelCount:1,baseArrayLayer:0,arrayLayerCount:1}),f=new ut(i,{source:s,shaderLayout:{bindings:[{type:"texture",name:"sourceTexture",group:0,location:0,viewDimension:"3d",sampleType:"float"},{type:"storage",name:"destinationTexture",group:0,location:1,format:e,viewDimension:"3d",access:"write-only"},{type:"uniform",name:"uniforms",group:0,location:2}]},bindings:{sourceTexture:m,destinationTexture:x,uniforms:r}}),y=Math.ceil(l/yt.x),b=Math.ceil(u/yt.y),_=Math.ceil(d/yt.z),p=i.beginComputePass({});f.dispatch(p,y,b,_),p.end(),i.submit(),f.destroy(),m.destroy(),x.destroy(),o=l,a=u,c=d}}finally{r.destroy()}}function Kt(i,t,e,s){let{format:r,dimension:n}=t,o=i.getTextureFormatCapabilities(r);if(e.filter(c=>!o[c]).length>0){let c=e.join(" + "),h=e.map(l=>`${l}=${o[l]}`).join(", ");throw new Error(`Cannot run ${s} mipmap generation for ${n} texture with format "${r}". Required capabilities: ${c}. Actual capabilities: ${h}.`)}}function Os(i){switch(i){case"2d":return"texture_2d<f32>";case"2d-array":return"texture_2d_array<f32>";case"cube":return"texture_cube<f32>";case"cube-array":return"texture_cube_array<f32>";default:throw new Error(`Unsupported render dimension "${i}" for mipmap generation.`)}}function ks(i){let t=Ds(i);return`
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
fn _touchUniform(uniforms: MipmapUniforms) {
|
|
13
|
-
let unusedSourceLayer = uniforms.sourceLayer;
|
|
14
|
-
}
|
|
15
|
-
|
|
16
|
-
const faceMat = array(
|
|
17
|
-
mat3x3f(
|
|
18
|
-
0.0, 0.0, -2.0,
|
|
19
|
-
0.0, -2.0, 0.0,
|
|
20
|
-
1.0, 1.0, 1.0
|
|
21
|
-
), // pos-x
|
|
22
|
-
mat3x3f(
|
|
23
|
-
0.0, 0.0, 2.0,
|
|
24
|
-
0.0, -2.0, 0.0,
|
|
25
|
-
-1.0, 1.0, -1.0
|
|
26
|
-
), // neg-x
|
|
27
|
-
mat3x3f(
|
|
28
|
-
2.0, 0.0, 0.0,
|
|
29
|
-
0.0, 0.0, 2.0,
|
|
30
|
-
-1.0, 1.0, -1.0
|
|
31
|
-
), // pos-y
|
|
32
|
-
mat3x3f(
|
|
33
|
-
2.0, 0.0, 0.0,
|
|
34
|
-
0.0, 0.0, -2.0,
|
|
35
|
-
-1.0, -1.0, 1.0
|
|
36
|
-
), // neg-y
|
|
37
|
-
mat3x3f(
|
|
38
|
-
2.0, 0.0, 0.0,
|
|
39
|
-
0.0, -2.0, 0.0,
|
|
40
|
-
-1.0, 1.0, 1.0
|
|
41
|
-
), // pos-z
|
|
42
|
-
mat3x3f(
|
|
43
|
-
-2.0, 0.0, 0.0,
|
|
44
|
-
0.0, -2.0, 0.0,
|
|
45
|
-
1.0, 1.0, -1.0
|
|
46
|
-
) // neg-z
|
|
47
|
-
);
|
|
48
|
-
|
|
49
|
-
struct FragmentInputs {
|
|
50
|
-
@builtin(position) position: vec4f,
|
|
51
|
-
@location(0) texcoord: vec2f
|
|
52
|
-
};
|
|
53
|
-
|
|
54
|
-
struct VertexOutput {
|
|
55
|
-
@builtin(position) position: vec4f,
|
|
56
|
-
@location(0) texcoord: vec2f
|
|
57
|
-
};
|
|
58
|
-
|
|
59
|
-
@group(0) @binding(0) var sourceSampler: sampler;
|
|
60
|
-
@group(0) @binding(1) var sourceTexture: ${Os(i)};
|
|
61
|
-
@group(0) @binding(2) var<uniform> uniforms: MipmapUniforms;
|
|
62
|
-
|
|
63
|
-
@vertex
|
|
64
|
-
fn vertexMain(
|
|
65
|
-
@builtin(vertex_index) vertexIndex: u32
|
|
66
|
-
) -> VertexOutput {
|
|
67
|
-
const positions = array(
|
|
68
|
-
vec2f(-1.0, -1.0),
|
|
69
|
-
vec2f(-1.0, 3.0),
|
|
70
|
-
vec2f( 3.0, -1.0)
|
|
71
|
-
);
|
|
72
|
-
|
|
73
|
-
let xy = positions[vertexIndex];
|
|
74
|
-
return VertexOutput(
|
|
75
|
-
vec4f(xy, 0.0, 1.0),
|
|
76
|
-
xy * vec2f(0.5, -0.5) + vec2f(0.5)
|
|
77
|
-
);
|
|
78
|
-
}
|
|
79
|
-
|
|
80
|
-
@fragment
|
|
81
|
-
fn fragmentMain(fsInput: VertexOutput) -> @location(0) vec4f {
|
|
82
|
-
_touchUniform(uniforms);
|
|
83
|
-
return ${t};
|
|
84
|
-
}
|
|
85
|
-
`}function Ds(i){let t="uniforms.sourceLayer";switch(i){case"2d":return"textureSampleLevel(sourceTexture, sourceSampler, fsInput.texcoord, 0.0)";case"2d-array":return`textureSampleLevel(sourceTexture, sourceSampler, fsInput.texcoord, i32(${t}), 0.0)`;case"cube":return`textureSampleLevel(sourceTexture, sourceSampler, faceMat[i32(${t})] * vec3f(fract(fsInput.texcoord), 1.0), 0.0)`;case"cube-array":return`textureSampleLevel(sourceTexture, sourceSampler, faceMat[i32(${t} % 6u)] * vec3f(fract(fsInput.texcoord), 1.0), i32(${t} / 6u), 0.0)`;default:throw new Error(`Unsupported render dimension "${i}" for mipmap generation.`)}}function Ns(i){return`
|
|
86
|
-
struct MipmapUniforms {
|
|
87
|
-
sourceWidth: u32,
|
|
88
|
-
sourceHeight: u32,
|
|
89
|
-
sourceDepth: u32,
|
|
90
|
-
destinationWidth: u32,
|
|
91
|
-
destinationHeight: u32,
|
|
92
|
-
destinationDepth: u32,
|
|
93
|
-
padding: u32,
|
|
94
|
-
};
|
|
95
|
-
|
|
96
|
-
@group(0) @binding(0) var sourceTexture: texture_3d<f32>;
|
|
97
|
-
@group(0) @binding(1) var destinationTexture: texture_storage_3d<${i}, write>;
|
|
98
|
-
@group(0) @binding(2) var<uniform> uniforms: MipmapUniforms;
|
|
99
|
-
|
|
100
|
-
@compute @workgroup_size(${yt.x}, ${yt.y}, ${yt.z})
|
|
101
|
-
fn main(@builtin(global_invocation_id) id: vec3<u32>) {
|
|
102
|
-
if (
|
|
103
|
-
id.x >= uniforms.destinationWidth ||
|
|
104
|
-
id.y >= uniforms.destinationHeight ||
|
|
105
|
-
id.z >= uniforms.destinationDepth
|
|
106
|
-
) {
|
|
107
|
-
return;
|
|
108
|
-
}
|
|
109
|
-
|
|
110
|
-
let sourceBase = id * 2u;
|
|
111
|
-
let sourceX0 = min(sourceBase.x, uniforms.sourceWidth - 1u);
|
|
112
|
-
let sourceY0 = min(sourceBase.y, uniforms.sourceHeight - 1u);
|
|
113
|
-
let sourceZ0 = min(sourceBase.z, uniforms.sourceDepth - 1u);
|
|
114
|
-
|
|
115
|
-
let sourceX1 = min(sourceBase.x + 1u, uniforms.sourceWidth - 1u);
|
|
116
|
-
let sourceY1 = min(sourceBase.y + 1u, uniforms.sourceHeight - 1u);
|
|
117
|
-
let sourceZ1 = min(sourceBase.z + 1u, uniforms.sourceDepth - 1u);
|
|
118
|
-
|
|
119
|
-
var sum = textureLoad(
|
|
120
|
-
sourceTexture,
|
|
121
|
-
vec3<i32>(i32(sourceX0), i32(sourceY0), i32(sourceZ0)),
|
|
122
|
-
0
|
|
123
|
-
);
|
|
124
|
-
sum += textureLoad(
|
|
125
|
-
sourceTexture,
|
|
126
|
-
vec3<i32>(i32(sourceX1), i32(sourceY0), i32(sourceZ0)),
|
|
127
|
-
0
|
|
128
|
-
);
|
|
129
|
-
sum += textureLoad(
|
|
130
|
-
sourceTexture,
|
|
131
|
-
vec3<i32>(i32(sourceX0), i32(sourceY1), i32(sourceZ0)),
|
|
132
|
-
0
|
|
133
|
-
);
|
|
134
|
-
sum += textureLoad(
|
|
135
|
-
sourceTexture,
|
|
136
|
-
vec3<i32>(i32(sourceX1), i32(sourceY1), i32(sourceZ0)),
|
|
137
|
-
0
|
|
138
|
-
);
|
|
139
|
-
sum += textureLoad(
|
|
140
|
-
sourceTexture,
|
|
141
|
-
vec3<i32>(i32(sourceX0), i32(sourceY0), i32(sourceZ1)),
|
|
142
|
-
0
|
|
143
|
-
);
|
|
144
|
-
sum += textureLoad(
|
|
145
|
-
sourceTexture,
|
|
146
|
-
vec3<i32>(i32(sourceX1), i32(sourceY0), i32(sourceZ1)),
|
|
147
|
-
0
|
|
148
|
-
);
|
|
149
|
-
sum += textureLoad(
|
|
150
|
-
sourceTexture,
|
|
151
|
-
vec3<i32>(i32(sourceX0), i32(sourceY1), i32(sourceZ1)),
|
|
152
|
-
0
|
|
153
|
-
);
|
|
154
|
-
sum += textureLoad(
|
|
155
|
-
sourceTexture,
|
|
156
|
-
vec3<i32>(i32(sourceX1), i32(sourceY1), i32(sourceZ1)),
|
|
157
|
-
0
|
|
158
|
-
);
|
|
159
|
-
|
|
160
|
-
textureStore(
|
|
161
|
-
destinationTexture,
|
|
162
|
-
vec3<i32>(i32(id.x), i32(id.y), i32(id.z)),
|
|
163
|
-
vec4<f32>(sum.xyz / 8.0, sum.w / 8.0)
|
|
164
|
-
);
|
|
165
|
-
}
|
|
166
|
-
`}var Ce=class{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error("Texture not initialized yet");return this._texture}get sampler(){if(!this._sampler)throw new Error("Sampler not initialized yet");return this._sampler}get view(){if(!this._view)throw new Error("View not initialized yet");return this._view}get[Symbol.toStringTag](){return"DynamicTexture"}toString(){return`DynamicTexture:"${this.id}":${this.texture.width}x${this.texture.height}px:(${this.isReady?"ready":"loading..."})`}constructor(t,e){this.device=t;let s=I("dynamic-texture"),r=e;this.props={...Ce.defaultProps,id:s,...e,data:null},this.id=this.props.id,this.ready=new Promise((n,o)=>{this.resolveReady=n,this.rejectReady=o}),this.initAsync(r)}async initAsync(t){try{let e=await this._loadAllData(t);this._checkNotDestroyed();let r=(()=>{if(this.props.width&&this.props.height)return{width:this.props.width,height:this.props.height};let h=ri(e);return h||{width:this.props.width||1,height:this.props.height||1}})();if(!r||r.width<=0||r.height<=0)throw new Error(`${this} size could not be determined or was zero`);let n={...this.props,...r,mipLevels:1,data:void 0};if(this.device.type==="webgpu"&&this.props.mipmaps){let h=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;n.usage|=h}let o=this.device.getMipLevelCount(n.width,n.height),a=this.props.mipLevels==="auto"?o:Math.max(1,Math.min(o,this.props.mipLevels??1)),c={...n,mipLevels:a};if(this._texture=this.device.createTexture(c),this._sampler=this.texture.sampler,this._view=this.texture.view,e.data)switch(e.dimension){case"1d":this.setTexture1DData(e.data);break;case"2d":this.setTexture2DData(e.data);break;case"3d":this.setTexture3DData(e.data);break;case"2d-array":this.setTextureArrayData(e.data);break;case"cube":this.setTextureCubeData(e.data);break;case"cube-array":this.setTextureCubeArrayData(e.data);break;default:throw new Error(`Unhandled dimension ${e.dimension}`)}this.props.mipmaps&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),N.log.info(0,`${this} created`)()}catch(e){let s=e instanceof Error?e:new Error(String(e));throw this.rejectReady(s),s}}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"?di(this.device,this.texture):N.log.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(t={}){this._checkReady();let e=t instanceof N.Sampler?t:this.device.createSampler(t);this.texture.setSampler(e),this._sampler=e}resize(t){if(this._checkReady(),t.width===this.texture.width&&t.height===this.texture.height)return!1;let e=this.texture;return this._texture=e.clone(t),this._sampler=this.texture.sampler,this._view=this.texture.view,e.destroy(),N.log.info(`${this} resized`),!0}getCubeFaceIndex(t){let e=Ae[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=oi(t);this._setTextureSubresources(e)}setTexture2DData(t,e=0){if(this._checkReady(),this.texture.props.dimension!=="2d")throw new Error(`${this} is not 2d`);let s=xt(e,t);this._setTextureSubresources(s)}setTexture3DData(t){if(this.texture.props.dimension!=="3d")throw new Error(`${this} is not 3d`);let e=ai(t);this._setTextureSubresources(e)}setTextureArrayData(t){if(this.texture.props.dimension!=="2d-array")throw new Error(`${this} is not 2d-array`);let e=ci(t);this._setTextureSubresources(e)}setTextureCubeData(t){if(this.texture.props.dimension!=="cube")throw new Error(`${this} is not cube`);let e=hi(t);this._setTextureSubresources(e)}setTextureCubeArrayData(t){if(this.texture.props.dimension!=="cube-array")throw new Error(`${this} is not cube-array`);let e=li(t);this._setTextureSubresources(e)}_setTextureSubresources(t){for(let e of t){let{z:s,mipLevel:r}=e;switch(e.type){case"external-image":let{image:n,flipY:o}=e;this.texture.copyExternalImage({image:n,z:s,mipLevel:r,flipY:o});break;case"texture-data":let{data:a}=e;this.texture.writeData(Fs(this.texture,a),{x:0,y:0,z:s,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 pi(t.data);return{dimension:t.dimension??"2d",data:e??null}}_checkNotDestroyed(){this.destroyed&&N.log.warn(`${this} already destroyed`)}_checkReady(){this.isReady||N.log.warn(`${this} Cannot perform this operation before ready`)}},Y=Ce;B(Y,"defaultProps",{...N.Texture.defaultProps,dimension:"2d",data:null,mipmaps:!1});function Fs(i,t){let{width:e,height:s,data:r}=t,{bytesPerPixel:n}=i.device.getTextureFormatInfo(i.format),o=e*n,a=Math.ceil(o/i.byteAlignment)*i.byteAlignment;if(a===o)return r;let c=new Uint8Array(r.buffer,r.byteOffset,r.byteLength),h=new Uint8Array(a*s);for(let l=0;l<s;l++){let u=l*o,d=l*a;h.set(c.subarray(u,u+o),d)}return h}async function pi(i){if(i=await i,Array.isArray(i))return await Promise.all(i.map(pi));if(i&&typeof i=="object"&&i.constructor===Object){let t=i,e=await Promise.all(Object.values(t)),s=Object.keys(t),r={};for(let n=0;n<s.length;n++)r[s[n]]=e[n];return r}return i}var ft=2,zs=1e4,Ie=class{device;id;source;vs;fs;pipelineFactory;shaderFactory;userData={};parameters;topology;bufferLayout;isInstanced=void 0;instanceCount=0;vertexCount;indexBuffer=null;bufferAttributes={};constantAttributes={};bindings={};vertexArray;transformFeedback=null;pipeline;shaderInputs;_uniformStore;_attributeInfos={};_gpuGeometry=null;props;_pipelineNeedsUpdate="newly created";_needsRedraw="initializing";_destroyed=!1;_lastDrawTimestamp=-1;get[Symbol.toStringTag](){return"Model"}toString(){return`Model(${this.id})`}constructor(t,e){this.props={...Ie.defaultProps,...e},e=this.props,this.id=e.id||I("model"),this.device=t,Object.assign(this.userData,e.userData);let s=Object.fromEntries(this.props.modules?.map(c=>[c.name,c])||[]),r=e.shaderInputs||new Z(s,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(r);let n=Bs(t),o=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.device.type==="webgpu"&&this.props.source){let{source:c,getUniforms:h}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:n,...this.props,modules:o});this.source=c,this._getModuleUniforms=h,this.props.shaderLayout||=t.getShaderLayout(this.source)}else{let{vs:c,fs:h,getUniforms:l}=this.props.shaderAssembler.assembleGLSLShaderPair({platformInfo:n,...this.props,modules:o});this.vs=c,this.fs=h,this._getModuleUniforms=l}this.vertexCount=this.props.vertexCount,this.instanceCount=this.props.instanceCount,this.topology=this.props.topology,this.bufferLayout=this.props.bufferLayout,this.parameters=this.props.parameters,e.geometry&&this.setGeometry(e.geometry),this.pipelineFactory=e.pipelineFactory||tt.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||et.getDefaultShaderFactory(this.device),this.pipeline=this._updatePipeline(),this.vertexArray=t.createVertexArray({shaderLayout:this.pipeline.shaderLayout,bufferLayout:this.pipeline.bufferLayout}),this._gpuGeometry&&this._setGeometryAttributes(this._gpuGeometry),"isInstanced"in e&&(this.isInstanced=e.isInstanced),e.instanceCount&&this.setInstanceCount(e.instanceCount),e.vertexCount&&this.setVertexCount(e.vertexCount),e.indexBuffer&&this.setIndexBuffer(e.indexBuffer),e.attributes&&this.setAttributes(e.attributes),e.constantAttributes&&this.setConstantAttributes(e.constantAttributes),e.bindings&&this.setBindings(e.bindings),e.transformFeedback&&(this.transformFeedback=e.transformFeedback)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.pipeline.vs),this.pipeline.fs&&this.shaderFactory.release(this.pipeline.fs),this._uniformStore.destroy(),this._gpuGeometry?.destroy(),this._destroyed=!0)}needsRedraw(){this._getBindingsUpdateTimestamp()>this._lastDrawTimestamp&&this.setNeedsRedraw("contents of bound textures or buffers updated");let t=this._needsRedraw;return this._needsRedraw=!1,t}setNeedsRedraw(t){this._needsRedraw||=t}predraw(){this.updateShaderInputs(),this.pipeline=this._updatePipeline()}draw(t){let e=this._areBindingsLoading();if(e)return T.log.info(ft,`>>> DRAWING ABORTED ${this.id}: ${e} not loaded`)(),!1;try{t.pushDebugGroup(`${this}.predraw(${t})`),this.predraw()}finally{t.popDebugGroup()}let s;try{t.pushDebugGroup(`${this}.draw(${t})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();let r=this._getBindings();this.pipeline.setBindings(r,{disableWarnings:this.props.disableWarnings});let{indexBuffer:n}=this.vertexArray,o=n?n.byteLength/(n.indexType==="uint32"?4:2):void 0;s=this.pipeline.draw({renderPass:t,vertexArray:this.vertexArray,isInstanced:this.isInstanced,vertexCount:this.vertexCount,instanceCount:this.instanceCount,indexCount:o,transformFeedback:this.transformFeedback||void 0,parameters:this.parameters,topology:this.topology})}finally{t.popDebugGroup(),this._logDrawCallEnd()}return this._logFramebuffer(t),s?(this._lastDrawTimestamp=this.device.timestamp,this._needsRedraw=!1):this._needsRedraw="waiting for resource initialization",s}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&Xe(this.device,t);if(e){this.setTopology(e.topology||"triangle-list");let s=new gt(this.bufferLayout);this.bufferLayout=s.mergeBufferLayouts(e.bufferLayout,this.bufferLayout),this.vertexArray&&this._setGeometryAttributes(e)}this._gpuGeometry=e}setTopology(t){t!==this.topology&&(this.topology=t,this._setPipelineNeedsUpdate("topology"))}setBufferLayout(t){let e=new gt(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){Xt(t,this.parameters,2)||(this.parameters=t,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(t){this.instanceCount=t,this.isInstanced===void 0&&t>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(t){this.vertexCount=t,this.setNeedsRedraw("vertexCount")}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new T.UniformStore(this.shaderInputs.modules);for(let[e,s]of Object.entries(this.shaderInputs.modules))if($s(s)){let r=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=r}this.setNeedsRedraw("shaderInputs")}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues()),this.setBindings(this.shaderInputs.getBindingValues()),this.setNeedsRedraw("shaderInputs")}setBindings(t){Object.assign(this.bindings,t),this.setNeedsRedraw("bindings")}setTransformFeedback(t){this.transformFeedback=t,this.setNeedsRedraw("transformFeedback")}setIndexBuffer(t){this.vertexArray.setIndexBuffer(t),this.setNeedsRedraw("indexBuffer")}setAttributes(t,e){let s=e?.disableWarnings??this.props.disableWarnings;t.indices&&T.log.warn(`Model:${this.id} setAttributes() - indexBuffer should be set using setIndexBuffer()`)(),this.bufferLayout=Je(this.pipeline.shaderLayout,this.bufferLayout);let r=new gt(this.bufferLayout);for(let[n,o]of Object.entries(t)){let a=r.getBufferLayout(n);if(!a){s||T.log.warn(`Model(${this.id}): Missing layout for buffer "${n}".`)();continue}let c=r.getAttributeNamesForBuffer(a),h=!1;for(let l of c){let u=this._attributeInfos[l];if(u){let d=this.device.type==="webgpu"?r.getBufferIndex(u.bufferName):u.location;this.vertexArray.setBuffer(d,o),h=!0}}!h&&!s&&T.log.warn(`Model(${this.id}): Ignoring buffer "${o.id}" for unknown attribute "${n}"`)()}this.setNeedsRedraw("attributes")}setConstantAttributes(t,e){for(let[s,r]of Object.entries(t)){let n=this._attributeInfos[s];n?this.vertexArray.setConstantWebGL(n.location,r):(e?.disableWarnings??this.props.disableWarnings)||T.log.warn(`Model "${this.id}: Ignoring constant supplied for unknown attribute "${s}"`)()}this.setNeedsRedraw("constants")}_areBindingsLoading(){for(let t of Object.values(this.bindings))if(t instanceof Y&&!t.isReady)return t.id;return!1}_getBindings(){let t={};for(let[e,s]of Object.entries(this.bindings))s instanceof Y?s.isReady&&(t[e]=s.texture):t[e]=s;return t}_getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof T.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof T.Buffer||e instanceof T.Texture?t=Math.max(t,e.updateTimestamp):e instanceof Y?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof T.Sampler||(t=Math.max(t,e.buffer.updateTimestamp));return t}_setGeometryAttributes(t){let e={...t.attributes};for(let[s]of Object.entries(e))!this.pipeline.shaderLayout.attributes.find(r=>r.name===s)&&s!=="positions"&&delete e[s];this.vertexCount=t.vertexCount,this.setIndexBuffer(t.indices||null),this.setAttributes(t.attributes,{disableWarnings:!0}),this.setAttributes(e,{disableWarnings:this.props.disableWarnings}),this.setNeedsRedraw("geometry attributes")}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate||=t,this.setNeedsRedraw(t)}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null,e=null;this.pipeline&&(T.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.pipeline.vs,e=this.pipeline.fs),this._pipelineNeedsUpdate=!1;let s=this.shaderFactory.createShader({id:`${this.id}-vertex`,stage:"vertex",source:this.source||this.vs,debugShaders:this.props.debugShaders}),r=null;this.source?r=s:this.fs&&(r=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"fragment",source:this.source||this.fs,debugShaders:this.props.debugShaders})),this.pipeline=this.pipelineFactory.createRenderPipeline({...this.props,bufferLayout:this.bufferLayout,topology:this.topology,parameters:this.parameters,bindings:this._getBindings(),vs:s,fs:r}),this._attributeInfos=(0,T.getAttributeInfosFromLayouts)(this.pipeline.shaderLayout,this.bufferLayout),t&&this.shaderFactory.release(t),e&&this.shaderFactory.release(e)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=T.log.level>3?0:zs;T.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,T.log.group(ft,`>>> DRAWING MODEL ${this.id}`,{collapsed:T.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=He(this.pipeline.shaderLayout,this.id);T.log.table(ft,t)();let e=this.shaderInputs.getDebugTable();T.log.table(ft,e)();let s=this._getAttributeDebugTable();T.log.table(ft,this._attributeInfos)(),T.log.table(ft,s)(),T.log.groupEnd(ft)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=this.device.props.debugFramebuffers;if(this._drawCount++,!e)return;let s=t.props.framebuffer;s&&Ke(s,{id:s.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,s]of Object.entries(this._attributeInfos)){let r=this.vertexArray.attributes[s.location];t[s.location]={name:e,type:s.shaderType,values:r?this._getBufferOrConstantValues(r,s.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,s=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:s.toString()}}return t}_getBufferOrConstantValues(t,e){let s=(0,T.getTypedArrayConstructor)(e);return(t instanceof T.Buffer?new s(t.debugData):t).toString()}},q=Ie;B(q,"defaultProps",{...T.RenderPipeline.defaultProps,source:void 0,vs:null,fs:null,id:"unnamed",handle:void 0,userData:{},defines:{},modules:[],geometry:null,indexBuffer:null,attributes:{},constantAttributes:{},varyings:[],isInstanced:void 0,instanceCount:0,vertexCount:0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,transformFeedback:void 0,shaderAssembler:mi.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function $s(i){return Boolean(i.uniformTypes&&!Us(i.uniformTypes))}function Bs(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}function Us(i){for(let t in i)return!1;return!0}var gi=O(z(),1),xi=O(ht(),1);var Zt=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=Zt.defaultProps){if(!Zt.isSupported(t))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=t,this.model=new q(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||(0,xi.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 gi.Buffer)return e.readAsync();let{buffer:s,byteOffset:r=0,byteLength:n=s.byteLength}=e;return s.readAsync(r,n)}},kt=Zt;B(kt,"defaultProps",{...q.defaultProps,outputs:void 0,feedbackBuffers:void 0});var yi=O(ht(),1);var Vs="transform_output",Qt=class{device;model;sampler;currentIndex=0;samplerTextureMap=null;bindings=[];resources={};constructor(t,e){this.device=t,this.sampler=t.createSampler({addressModeU:"clamp-to-edge",addressModeV:"clamp-to-edge",minFilter:"nearest",magFilter:"nearest",mipmapFilter:"nearest"}),this.model=new q(this.device,{id:e.id||I("texture-transform-model"),fs:e.fs||(0,yi.getPassthroughFS)({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:Vs}),vertexCount:e.vertexCount,...e}),this._initialize(e),Object.seal(this)}destroy(){this.model.destroy();for(let t of this.bindings)t.framebuffer?.destroy()}delete(){this.destroy()}run(t){let{framebuffer:e}=this.bindings[this.currentIndex],s=this.device.beginRenderPass({framebuffer:e,...t});this.model.draw(s),s.end(),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:s,targetTexture:r}){if(t||(t={sourceBuffers:{},sourceTextures:{},targetTexture:null}),Object.assign(t.sourceTextures,s),Object.assign(t.sourceBuffers,e),r){t.targetTexture=r;let{width:n,height:o}=r;t.framebuffer&&t.framebuffer.destroy(),t.framebuffer=this.device.createFramebuffer({id:"transform-framebuffer",width:n,height:o,colorAttachments:[r]}),t.framebuffer.resize({width:n,height:o})}return t}_setSourceTextureParameters(){let t=this.currentIndex,{sourceTextures:e}=this.bindings[t];for(let s in e)e[s].sampler=this.sampler}};var V=class{id;topology;vertexCount;indices;attributes;userData={};constructor(t){let{attributes:e={},indices:s=null,vertexCount:r=null}=t;this.id=t.id||I("geometry"),this.topology=t.topology,s&&(this.indices=ArrayBuffer.isView(s)?{value:s,size:1}:s),this.attributes={};for(let[n,o]of Object.entries(e)){let a=ArrayBuffer.isView(o)?{value:o}:o;if(!ArrayBuffer.isView(a.value))throw new Error(`${this._print(n)}: must be typed array or object with value as typed array`);if((n==="POSITION"||n==="positions")&&!a.size&&(a.size=3),n==="indices"){if(this.indices)throw new Error("Multiple indices detected");this.indices=a}else this.attributes[n]=a}this.indices&&this.indices.isIndexed!==void 0&&(this.indices=Object.assign({},this.indices),delete this.indices.isIndexed),this.vertexCount=r||this._calculateVertexCount(this.attributes,this.indices)}getVertexCount(){return this.vertexCount}getAttributes(){return this.indices?{indices:this.indices,...this.attributes}:this.attributes}_print(t){return`Geometry ${this.id} attribute ${t}`}_setAttributes(t,e){return this}_calculateVertexCount(t,e){if(e)return e.value.length;let s=1/0;for(let r of Object.values(t)){let{value:n,size:o,constant:a}=r;!a&&n&&o!==void 0&&o>=1&&(s=Math.min(s,n.length/o))}return s}};var js=`struct VertexInputs {
|
|
167
|
-
@location(0) clipSpacePosition: vec2<f32>,
|
|
168
|
-
@location(1) texCoord: vec2<f32>,
|
|
169
|
-
@location(2) coordinate: vec2<f32>
|
|
7
|
+
"use strict";var __exports__=(()=>{var Hn=Object.create;var Ct=Object.defineProperty;var Wn=Object.getOwnPropertyDescriptor;var Yn=Object.getOwnPropertyNames;var Kn=Object.getPrototypeOf,Zn=Object.prototype.hasOwnProperty;var Qn=(i,t,e)=>t in i?Ct(i,t,{enumerable:!0,configurable:!0,writable:!0,value:e}):i[t]=e;var pi=(i,t)=>()=>(t||i((t={exports:{}}).exports,t),t.exports),Jn=(i,t)=>{for(var e in t)Ct(i,e,{get:t[e],enumerable:!0})},Yt=(i,t,e,n)=>{if(t&&typeof t=="object"||typeof t=="function")for(let r of Yn(t))!Zn.call(i,r)&&r!==e&&Ct(i,r,{get:()=>t[r],enumerable:!(n=Wn(t,r))||n.enumerable});return i},Kt=(i,t,e)=>(Yt(i,t,"default"),e&&Yt(e,t,"default")),R=(i,t,e)=>(e=i!=null?Hn(Kn(i)):{},Yt(t||!i||!i.__esModule?Ct(e,"default",{value:i,enumerable:!0}):e,i)),tr=i=>Yt(Ct({},"__esModule",{value:!0}),i);var K=(i,t,e)=>(Qn(i,typeof t!="symbol"?t+"":t,e),e);var U=pi((Ks,gi)=>{gi.exports=globalThis.luma});var rt=pi((xo,Mi)=>{Mi.exports=globalThis.luma});var Vt={};Jn(Vt,{AnimationLoop:()=>lt,AnimationLoopTemplate:()=>Jt,AsyncTexture:()=>Ws,BackgroundTextureModel:()=>_t,BufferTransform:()=>zt,ClipSpace:()=>st,Computation:()=>Gt,ConeGeometry:()=>ct,CubeGeometry:()=>be,CylinderGeometry:()=>Me,DirectionalLightModel:()=>xe,DynamicTexture:()=>z,GPUGeometry:()=>pt,Geometry:()=>V,GroupNode:()=>ft,IcoSphereGeometry:()=>_e,KeyFrames:()=>Qt,LegacyPickingManager:()=>Le,Material:()=>Mt,MaterialFactory:()=>bt,Model:()=>W,ModelNode:()=>ye,PickingManager:()=>Ut,PlaneGeometry:()=>Ie,PointLightModel:()=>pe,ScenegraphNode:()=>it,ShaderInputs:()=>$,ShaderPassRenderer:()=>we,SphereGeometry:()=>It,SpotLightModel:()=>ge,Swap:()=>Tt,SwapBuffers:()=>ve,SwapFramebuffers:()=>Pt,TextureTransform:()=>se,Timeline:()=>Zt,TruncatedConeGeometry:()=>at,cancelAnimationFramePolyfill:()=>ee,colorPicking:()=>$t,indexPicking:()=>Se,legacyColorPicking:()=>Un,loadImage:()=>On,loadImageBitmap:()=>En,makeAnimationLoop:()=>bi,makeRandomGenerator:()=>Ln,picking:()=>jn,requestAnimationFramePolyfill:()=>te,resolvePickingBackend:()=>zn,resolvePickingMode:()=>Pe,setPathPrefix:()=>Cn,supportsIndexPicking:()=>fi});Kt(Vt,R(U(),1));var er=1,ir=1,Zt=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=er++,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=ir++;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 Qt=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 Jt=class{constructor(t){}async onInitialize(t){return null}};var xi=R(U(),1);function te(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 ee(i){let t=typeof window<"u"?window.cancelAnimationFrame||window.webkitCancelAnimationFrame||window.mozCancelAnimationFrame:null;if(t){t.call(window,i);return}clearTimeout(i)}function Et(){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=Et(),this._timerPending=!0,this}timeEnd(){return this._timerPending?(this.addTime(Et()-this._startTime),this._timerPending=!1,this._checkSampling(),this):this}getSampleAverageCount(){return this.sampleSize>0?this.lastSampleCount/this.sampleSize:0}getSampleAverageTime(){return this.sampleSize>0?this.lastSampleTime/this.sampleSize:0}getSampleHz(){return this.lastSampleTime>0?this.sampleSize/(this.lastSampleTime/1e3):0}getAverageCount(){return this.samples>0?this.count/this.samples:0}getAverageTime(){return this.samples>0?this.time/this.samples:0}getHz(){return this.time>0?this.samples/(this.time/1e3):0}_checkSampling(){this._samples===this.sampleSize&&(this.lastSampleTime=this._time,this.lastSampleCount=this._count,this.count+=this._count,this.time+=this._time,this.samples+=this._samples,this._time=0,this._count=0,this._samples=0)}};var mt=class{constructor(t){this.stats={},this.id=t.id,this.stats={},this._initializeStats(t.stats),Object.seal(this)}get(t,e="count"){return this._getOrCreate({name:t,type:e})}get size(){return Object.keys(this.stats).length}reset(){for(let t of Object.values(this.stats))t.reset();return this}forEach(t){for(let e of Object.values(this.stats))t(e)}getTable(){let t={};return this.forEach(e=>{t[e.name]={time:e.time||0,count:e.count||0,average:e.getAverageTime()||0,hz:e.getHz()||0}}),t}_initializeStats(t=[]){t.forEach(e=>this._getOrCreate(e))}_getOrCreate(t){let{name:e,type:n}=t,r=this.stats[e];return r||(t instanceof ht?r=t:r=new ht(e,n),this.stats[e]=r),r}};var nr=0,rr="Animation Loop",Ce=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={...Ce.defaultAnimationLoopProps,...t},t=this.props,!t.device)throw new Error("No device provided");this.stats=t.stats||new mt({id:`animation-loop-${nr++}`}),this.sharedStats=xi.luma.stats.get(rr),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=te(this._animationFrame.bind(this)))}_cancelAnimationFrame(){this._animationFrameId!==null&&(ee(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=Ce;K(lt,"defaultAnimationLoopProps",{device:null,onAddHTML:()=>"",onInitialize:async()=>null,onRender:()=>{},onFinalize:()=>{},onError:t=>console.error(t),stats:void 0,autoResizeViewport:!1});var yi=R(U(),1);function bi(i,t){let e=null,n=t?.device||yi.luma.createDevice({id:"animation-loop",adapters:t?.adapters,createCanvasContext:!0}),r=new lt({...t,device:n,async onInitialize(s){or(s.animationLoop.device);try{return e=new i(s),await e?.onInitialize(s)}catch(o){return sr(s.animationLoop.device,o),null}},onRender:s=>e?.onRender(s),onFinalize:s=>e?.onFinalize(s)});return r.getInfo=()=>this.AnimationLoopTemplateCtor.info,r}function sr(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 or(i){if(!i)return;let t=document.getElementById("animation-loop-error");t&&t.remove()}var w=R(U(),1),Di=R(rt(),1);var Ot=R(U(),1);var Ee={};function S(i="id"){Ee[i]=Ee[i]||1;let t=Ee[i]++;return`${i}-${t}`}var pt=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&Ot.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 _i(i,t){if(t instanceof pt)return t;let e=ar(i,t),{attributes:n,bufferLayout:r}=cr(i,t);return new pt({topology:t.topology||"triangle-list",bufferLayout:r,vertexCount:t.vertexCount,indices:e,attributes:n})}function ar(i,t){if(!t.indices)return;let e=t.indices.value;return i.createBuffer({usage:Ot.Buffer.INDEX,data:e})}function cr(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"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:Ot.vertexFormatDecoder.getVertexFormatFromAttribute(c,h,l)})}}let r=t._calculateVertexCount(t.attributes,t.indices);return{attributes:n,bufferLayout:e,vertexCount:r}}function Ii(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 F=null,Oe=null;function vi(i,{id:t,minimap:e,opaque:n,top:r="0",left:s="0",rgbaScale:o=1}){F||(F=document.createElement("canvas"),F.id=t,F.title=t,F.style.zIndex="100",F.style.position="absolute",F.style.top=r,F.style.left=s,F.style.border="blue 5px solid",F.style.transform="scaleY(-1)",document.body.appendChild(F),Oe=F.getContext("2d")),(F.width!==i.width||F.height!==i.height)&&(F.width=i.width/2,F.height=i.height/2,F.style.width="400px",F.style.height="400px");let a=i.device.readPixelsToArrayWebGL(i),c=Oe?.createImageData(i.width,i.height);if(c){for(let l=0;l<a.length;l+=4)c.data[0+l+0]=a[l+0]*o,c.data[0+l+1]=a[l+1]*o,c.data[0+l+2]=a[l+2]*o,c.data[0+l+3]=n?255:a[l+3]*o;Oe?.putImageData(c,0,0)}}function ie(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(!ie(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)||!ie(i[s],t[s],e-1))return!1;return!0}return!1}var wi=R(U(),1),gt=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 xt(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 hr(r.name)){let o=e.bindings.find(a=>a.name===s);o?.group===0&&(o.group=r.group)}return e}function yt(i){return Boolean(i.uniformTypes&&!lr(i.uniformTypes))}function hr(i){let t=new Set([i,`${i}Uniforms`]);return i.endsWith("Uniforms")||t.add(`${i}Sampler`),[...t]}function lr(i){for(let t in i)return!1;return!0}var ne=R(U(),1),Ei=R(rt(),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 kt(i){return Pi(i)||Si(i)}function dr(i){return kt(i)||typeof i=="number"||typeof i=="boolean"}function Li(i,t={}){let e={bindings:{},uniforms:{}};return Object.keys(i).forEach(n=>{let r=i[n];Object.prototype.hasOwnProperty.call(t,n)||dr(r)?e.uniforms[n]=r:e.bindings[n]=r}),e}var $=class{options={disableWarnings:!1};modules;moduleUniforms;moduleBindings;constructor(t,e){Object.assign(this.options,e);let n=(0,Ei.getShaderModuleDependencies)(Object.values(t).filter(ur));for(let r of n)t[r.name]=r;ne.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&&ne.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||ne.log.warn(`Module ${e} not found`)();continue}let o=this.moduleUniforms[n],a=this.moduleBindings[n],c=s.getUniforms?.(r,o)||r,{uniforms:h,bindings:l}=Li(c,s.uniformTypes);this.moduleUniforms[n]=Ci(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]=Ci({},t.defaultUniforms||{},t.uniformTypes),this.moduleBindings[e]={}}};function Ci(i={},t={},e={}){let n={...i};for(let[r,s]of Object.entries(t))s!==void 0&&(n[r]=ke(i[r],s,e[r]));return n}function ke(i,t,e){if(!e||typeof e=="string")return Rt(t);if(Array.isArray(e)){if(Re(t)||!Array.isArray(t))return Rt(t);let o=Array.isArray(i)&&!Re(i)?[...i]:[],a=o.slice();for(let c=0;c<t.length;c++){let h=t[c];h!==void 0&&(a[c]=ke(o[c],h,e[0]))}return a}if(!Ne(t))return Rt(t);let n=e,r=Ne(i)?i:{},s={...r};for(let[o,a]of Object.entries(t))a!==void 0&&(s[o]=ke(r[o],a,n[o]));return s}function Rt(i){return ArrayBuffer.isView(i)?Array.prototype.slice.call(i):Array.isArray(i)?Re(i)?i.slice():i.map(e=>e===void 0?void 0:Rt(e)):Ne(i)?Object.fromEntries(Object.entries(i).map(([t,e])=>[t,e===void 0?void 0:Rt(e)])):i}function Re(i){return ArrayBuffer.isView(i)||Array.isArray(i)&&(i.length===0||typeof i[0]=="number")}function Ne(i){return Boolean(i)&&typeof i=="object"&&!Array.isArray(i)&&!ArrayBuffer.isView(i)}function ur(i){return Boolean(i?.dependencies)}var k=R(U(),1);var Ft=R(U(),1);var De={"+X":0,"-X":1,"+Y":2,"-Y":3,"+Z":4,"-Z":5};function Nt(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=Nt(e);if(!n)return null;let{width:r}=Dt(n);return{width:r,height:1}}case"2d":{let n=Nt(e);return n?Dt(n):null}case"3d":case"2d-array":{if(!Array.isArray(e)||e.length===0)return null;let n=Nt(e[0]);return n?Dt(n):null}case"cube":{let n=Object.keys(e)[0]??null;if(!n)return null;let r=e[n],s=Nt(r);return s?Dt(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=Nt(n[r]);return s?Dt(s):null}default:return null}}function Dt(i){if((0,Ft.isExternalImage)(i))return(0,Ft.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 fr(i){return typeof i=="object"&&i!==null&&"data"in i&&"width"in i&&"height"in i}function mr(i){return ArrayBuffer.isView(i)}function Fe(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 ki(i){let t=De[i];if(t===void 0)throw new Error(`Invalid cube face: ${i}`);return t}function pr(i,t){return 6*i+ki(t)}function Be(i){throw new Error("setTexture1DData not supported in WebGL.")}function gr(i){return Array.isArray(i)?i:[i]}function dt(i,t,e,n){let r=gr(t),s=i,o=[];for(let a=0;a<r.length;a++){let c=r[a];if((0,Ft.isExternalImage)(c))o.push({type:"external-image",image:c,z:s,mipLevel:a});else if(fr(c))o.push({type:"texture-data",data:c,textureFormat:Fe(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 ze(i){let t=[];for(let e=0;e<i.length;e++)t.push(...dt(e,i[e]));return t}function je(i){let t=[];for(let e=0;e<i.length;e++)t.push(...dt(e,i[e]));return t}function Ge(i){let t=[];for(let[e,n]of Object.entries(i)){let r=ki(e);t.push(...dt(r,n))}return t}function Ue(i){let t=[];return i.forEach((e,n)=>{for(let[r,s]of Object.entries(e)){let o=pr(n,r);t.push(...dt(o,s))}}),t}var Ve=class{device;id;props;_texture=null;_sampler=null;_view=null;ready;isReady=!1;destroyed=!1;resolveReady=()=>{};rejectReady=()=>{};get texture(){if(!this._texture)throw new Error("Texture not initialized yet");return this._texture}get sampler(){if(!this._sampler)throw new Error("Sampler not initialized yet");return this._sampler}get view(){if(!this._view)throw new Error("View not initialized yet");return this._view}get[Symbol.toStringTag](){return"DynamicTexture"}toString(){return`DynamicTexture:"${this.id}":${this.texture.width}x${this.texture.height}px:(${this.isReady?"ready":"loading..."})`}constructor(t,e){this.device=t;let n=S("dynamic-texture"),r=e;this.props={...Ve.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?xr({...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 f=Oi(e);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=yr(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=k.Texture.SAMPLE|k.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"?k.Texture.SAMPLE|k.Texture.STORAGE|k.Texture.COPY_DST|k.Texture.COPY_SRC:k.Texture.SAMPLE|k.Texture.RENDER|k.Texture.COPY_DST|k.Texture.COPY_SRC;l.usage|=f}let u=this.device.getMipLevelCount(l.width,l.height),g=c.hasExplicitMipChain?c.mipLevels:this.props.mipLevels==="auto"?u:Math.max(1,Math.min(u,this.props.mipLevels??1)),p={...l,mipLevels:g};this._texture=this.device.createTexture(p),this._sampler=this.texture.sampler,this._view=this.texture.view,c.subresources.length&&this._setTextureSubresources(c.subresources),this.props.mipmaps&&!c.hasExplicitMipChain&&!d&&k.log.warn(`${this} skipping auto-generated mipmaps for compressed texture format`)(),d&&this.generateMipmaps(),this.isReady=!0,this.resolveReady(this.texture),k.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):k.log.warn(`${this} mipmaps not supported on ${this.device.type}`)}setSampler(t={}){this._checkReady();let e=t instanceof k.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:k.Buffer.COPY_DST|k.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(),k.log.info(`${this} resized`),!0}getCubeFaceIndex(t){let e=De[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=Be(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=ze(t);this._setTextureSubresources(e)}setTextureArrayData(t){if(this.texture.props.dimension!=="2d-array")throw new Error(`${this} is not 2d-array`);let e=je(t);this._setTextureSubresources(e)}setTextureCubeData(t){if(this.texture.props.dimension!=="cube")throw new Error(`${this} is not cube`);let e=Ge(t);this._setTextureSubresources(e)}setTextureCubeArrayData(t){if(this.texture.props.dimension!=="cube-array")throw new Error(`${this} is not cube-array`);let e=Ue(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 $e(t.data);return{dimension:t.dimension??"2d",data:e??null}}_checkNotDestroyed(){this.destroyed&&k.log.warn(`${this} already destroyed`)}_checkReady(){this.isReady||k.log.warn(`${this} Cannot perform this operation before ready`)}},z=Ve;K(z,"defaultProps",{...k.Texture.defaultProps,dimension:"2d",data:null,mipmaps:!1});function xr(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 Be(i.data);case"2d":return dt(0,i.data,t,e);case"3d":return ze(i.data);case"2d-array":return je(i.data);case"cube":return Ge(i.data);case"cube-array":return Ue(i.data);default:throw new Error(`Unhandled dimension ${i.dimension}`)}}function yr(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 u=[...d].sort((I,m)=>I.mipLevel-m.mipLevel),g=u[0];if(!g||g.mipLevel!==0)throw new Error(`DynamicTexture: slice ${l} is missing mip level 0`);let p=Ni(i,g);if(p.width!==e.width||p.height!==e.height)throw new Error(`DynamicTexture: slice ${l} base level dimensions ${p.width}x${p.height} do not match expected ${e.width}x${e.height}`);let f=Ri(g);if(f){if(o&&o!==f)throw new Error(`DynamicTexture: slice ${l} base level format "${f}" does not match texture format "${o}"`);o=f}let y=o&&i.isTextureFormatCompressed(o)?br(i,p.width,p.height,o):i.getMipLevelCount(p.width,p.height),M=0;for(let I=0;I<u.length;I++){let m=u[I];if(!m||m.mipLevel!==I||I>=y)break;let x=Ni(i,m),b=Math.max(1,p.width>>I),_=Math.max(1,p.height>>I);if(x.width!==b||x.height!==_)break;let T=Ri(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 Ri(i){if(i.type==="texture-data")return i.textureFormat??Fe(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 br(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 $e(i){if(i=await i,Array.isArray(i))return await Promise.all(i.map($e));if(i&&typeof i=="object"&&i.constructor===Object){let t=i,e=await Promise.all(Object.values(t).map($e)),n=Object.keys(t),r={};for(let s=0;s<n.length;s++)r[n[s]]=e[s];return r}return i}var ut=2,Mr=1e4,Xe=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={...Xe.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 $(n,{disableWarnings:this.props.disableWarnings});this.setShaderInputs(r);let s=_r(t),o=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];if(this.props.shaderLayout=xt(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=xt(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(ut,`>>> DRAWING ABORTED ${this.id}: ${e} not loaded`)(),!1;try{t.pushDebugGroup(`${this}.predraw(${t})`),this.predraw()}finally{t.popDebugGroup()}let n;try{t.pushDebugGroup(`${this}.draw(${t})`),this._logDrawCallStart(),this.pipeline=this._updatePipeline();let r=this._getBindings(),s=this._getBindGroups(),{indexBuffer:o}=this.vertexArray,a=o?o.byteLength/(o.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:a,transformFeedback:this.transformFeedback||void 0,bindings:r,bindGroups:s,_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):this._needsRedraw="waiting for resource initialization",n}setGeometry(t){this._gpuGeometry?.destroy();let e=t&&_i(this.device,t);if(e){this.setTopology(e.topology||"triangle-list");let n=new gt(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 gt(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){ie(t,this.parameters,2)||(this.parameters=t,this._setPipelineNeedsUpdate("parameters"))}setInstanceCount(t){this.instanceCount=t,this.isInstanced===void 0&&t>0&&(this.isInstanced=!0),this.setNeedsRedraw("instanceCount")}setVertexCount(t){this.vertexCount=t,this.setNeedsRedraw("vertexCount")}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new w.UniformStore(this.shaderInputs.modules);for(let[e,n]of Object.entries(this.shaderInputs.modules))if(yt(n)&&!this.material?.ownsModule(e)){let r=this._uniformStore.getManagedUniformBuffer(this.device,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 gt(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 u=this.device.type==="webgpu"?r.getBufferIndex(d.bufferName):d.location;this.vertexArray.setBuffer(u,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 z&&!t.isReady)return t.id;for(let t of Object.values(this.material?.bindings||{}))if(t instanceof z&&!t.isReady)return t.id;return!1}_getBindings(){let t={};for(let[e,n]of Object.entries(this.bindings))n instanceof z?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 z?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:Mr;w.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,w.log.group(ut,`>>> DRAWING MODEL ${this.id}`,{collapsed:w.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=Ii(this.pipeline.shaderLayout,this.id);w.log.table(ut,t)();let e=this.shaderInputs.getDebugTable();w.log.table(ut,e)();let n=this._getAttributeDebugTable();w.log.table(ut,this._attributeInfos)(),w.log.table(ut,n)(),w.log.groupEnd(ut)(),this._logOpen=!1}}_drawCount=0;_logFramebuffer(t){let e=this.device.props.debugFramebuffers;if(this._drawCount++,!e)return;let n=t.props.framebuffer;n&&vi(n,{id:n.id,minimap:!0})}_getAttributeDebugTable(){let t={};for(let[e,n]of Object.entries(this._attributeInfos)){let r=this.vertexArray.attributes[n.location];t[n.location]={name:e,type:n.shaderType,values:r?this._getBufferOrConstantValues(r,n.bufferDataType):"null"}}if(this.vertexArray.indexBuffer){let{indexBuffer:e}=this.vertexArray,n=e.indexType==="uint32"?new Uint32Array(e.debugData):new Uint16Array(e.debugData);t.indices={name:"indices",type:e.indexType,values:n.toString()}}return t}_getBufferOrConstantValues(t,e){let n=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}},W=Xe;K(W,"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:Di.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0,disableWarnings:void 0});function _r(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}var J=R(U(),1);var Bt=3,bt=class{device;modules;_materialBindingNames;_materialModuleNames;constructor(t,e={}){this.device=t,this.modules=e.modules||[];let n=new $(Object.fromEntries(this.modules.map(r=>[r.name,r])));this._materialBindingNames=Ir(n),this._materialModuleNames=vr(n)}createMaterial(t={}){return new Mt(this.device,{...t,factory:this})}getBindingNames(){return Array.from(this._materialBindingNames)}ownsBinding(t){if(this._materialBindingNames.has(t))return!0;let e=qe(t);return e?this._materialModuleNames.has(e):!1}ownsModule(t){return this._materialModuleNames.has(t)}getBindingsByGroup(t){return Object.keys(t).length>0?{[Bt]:t}:{}}};function qe(i){return i.endsWith("Uniforms")?i.slice(0,-8):null}function Ir(i){let t=new Set;for(let e of Object.values(i.modules))for(let n of e.bindingLayout||[])n.group===Bt&&t.add(n.name);return t}function vr(i){let t=new Set;for(let e of Object.values(i.modules))e.name&&e.bindingLayout?.some(n=>n.group===Bt&&n.name===e.name)&&t.add(e.name);return t}var Mt=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 $(n),this._uniformStore=new J.UniformStore(this.shaderInputs.modules);for(let[r,s]of Object.entries(this.shaderInputs.modules))if(this.ownsModule(r)&&yt(s)){let o=this._uniformStore.getManagedUniformBuffer(this.device,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))qe(e)||(t[e]=n);return t}getBindings(){let t={},e=t;for(let[n,r]of Object.entries(this.bindings))r instanceof z?r.isReady&&(e[n]=r.texture):e[n]=r;return t}getBindingsByGroup(){return this.factory.getBindingsByGroup(this.getBindings())}getBindGroupCacheKey(t){return t===Bt?this._bindGroupCacheToken:null}getBindingsUpdateTimestamp(){let t=0;for(let e of Object.values(this.bindings))e instanceof J.TextureView?t=Math.max(t,e.texture.updateTimestamp):e instanceof J.Buffer||e instanceof J.Texture?t=Math.max(t,e.updateTimestamp):e instanceof z?t=e.texture?Math.max(t,e.texture.updateTimestamp):1/0:e instanceof J.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 Fi=R(U(),1),Bi=R(rt(),1);var re=class{device;model;transformFeedback;static isSupported(t){return t?.info?.type==="webgl"}constructor(t,e=re.defaultProps){if(!re.isSupported(t))throw new Error("BufferTransform not yet implemented on WebGPU");this.device=t,this.model=new W(this.device,{id:e.id||"buffer-transform-model",fs:e.fs||(0,Bi.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 Fi.Buffer)return e.readAsync();let{buffer:n,byteOffset:r=0,byteLength:s=n.byteLength}=e;return n.readAsync(r,s)}},zt=re;K(zt,"defaultProps",{...W.defaultProps,outputs:void 0,feedbackBuffers:void 0});var zi=R(rt(),1);var wr="transform_output",se=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 W(this.device,{id:e.id||S("texture-transform-model"),fs:e.fs||(0,zi.getPassthroughFS)({input:e.targetTextureVarying,inputChannels:e.targetTextureChannels,output:wr}),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 V=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 Ar=`struct VertexInputs {
|
|
8
|
+
@location(0) clipSpacePositions: vec2<f32>,
|
|
9
|
+
@location(1) texCoords: vec2<f32>,
|
|
10
|
+
@location(2) coordinates: vec2<f32>
|
|
170
11
|
}
|
|
171
12
|
|
|
172
13
|
struct FragmentInputs {
|
|
@@ -179,13 +20,13 @@ struct FragmentInputs {
|
|
|
179
20
|
@vertex
|
|
180
21
|
fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
|
|
181
22
|
var outputs: FragmentInputs;
|
|
182
|
-
outputs.Position = vec4(inputs.
|
|
183
|
-
outputs.position = inputs.
|
|
184
|
-
outputs.coordinate = inputs.
|
|
185
|
-
outputs.uv = inputs.
|
|
23
|
+
outputs.Position = vec4(inputs.clipSpacePositions, 0., 1.);
|
|
24
|
+
outputs.position = inputs.clipSpacePositions;
|
|
25
|
+
outputs.coordinate = inputs.coordinates;
|
|
26
|
+
outputs.uv = inputs.texCoords;
|
|
186
27
|
return outputs;
|
|
187
28
|
}
|
|
188
|
-
`,
|
|
29
|
+
`,Tr=`#version 300 es
|
|
189
30
|
in vec2 clipSpacePositions;
|
|
190
31
|
in vec2 texCoords;
|
|
191
32
|
in vec2 coordinates;
|
|
@@ -200,26 +41,26 @@ void main(void) {
|
|
|
200
41
|
coordinate = coordinates;
|
|
201
42
|
uv = texCoords;
|
|
202
43
|
}
|
|
203
|
-
`,
|
|
204
|
-
${e.source}`}),super(t,{id:e.id||
|
|
44
|
+
`,ji=[-1,-1,1,-1,-1,1,1,1],st=class extends W{constructor(t,e){let n=ji.map(r=>r===-1?0:r);e.source&&(e={...e,source:`${Ar}
|
|
45
|
+
${e.source}`}),super(t,{id:e.id||S("clip-space"),...e,vs:Tr,vertexCount:4,geometry:new V({topology:"triangle-strip",vertexCount:4,attributes:{clipSpacePositions:{size:2,value:new Float32Array(ji)},texCoords:{size:2,value:new Float32Array(n)},coordinates:{size:2,value:new Float32Array(n)}}})})}};var Pr={name:"background",uniformTypes:{scale:"vec2<f32>"}},Sr=`@group(0) @binding(0) var backgroundTexture: texture_2d<f32>;
|
|
205
46
|
@group(0) @binding(1) var backgroundTextureSampler: sampler;
|
|
206
47
|
struct backgroundUniforms {
|
|
207
48
|
scale: vec2<f32>,
|
|
208
49
|
};
|
|
209
50
|
@group(0) @binding(2) var<uniform> background: backgroundUniforms;
|
|
210
51
|
|
|
211
|
-
fn billboardTexture_getTextureUV(
|
|
52
|
+
fn billboardTexture_getTextureUV(uv: vec2<f32>) -> vec2<f32> {
|
|
212
53
|
let scale: vec2<f32> = background.scale;
|
|
213
|
-
var position: vec2<f32> = (
|
|
54
|
+
var position: vec2<f32> = (uv - vec2<f32>(0.5, 0.5)) / scale + vec2<f32>(0.5, 0.5);
|
|
214
55
|
return position;
|
|
215
56
|
}
|
|
216
57
|
|
|
217
58
|
@fragment
|
|
218
59
|
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
|
|
219
|
-
let position: vec2<f32> = billboardTexture_getTextureUV(inputs.
|
|
60
|
+
let position: vec2<f32> = billboardTexture_getTextureUV(inputs.uv);
|
|
220
61
|
return textureSample(backgroundTexture, backgroundTextureSampler, position);
|
|
221
62
|
}
|
|
222
|
-
`,
|
|
63
|
+
`,Lr=`#version 300 es
|
|
223
64
|
precision highp float;
|
|
224
65
|
|
|
225
66
|
uniform sampler2D backgroundTexture;
|
|
@@ -240,47 +81,110 @@ void main(void) {
|
|
|
240
81
|
vec2 position = billboardTexture_getTextureUV(coordinate);
|
|
241
82
|
fragColor = texture(backgroundTexture, position);
|
|
242
83
|
}
|
|
243
|
-
`,bt=class extends it{backgroundTexture=null;constructor(t,e){if(super(t,{id:e.id||"background-texture-model",source:qs,fs:Ys,modules:[Ws],parameters:{depthWriteEnabled:!1,...e.blend?{blend:!0,blendColorOperation:"add",blendAlphaOperation:"add",blendColorSrcFactor:"one",blendColorDstFactor:"one-minus-src",blendAlphaSrcFactor:"one",blendAlphaDstFactor:"one-minus-src-alpha"}:{}}}),!e.backgroundTexture)throw new Error("BackgroundTextureModel requires a backgroundTexture prop");this.setProps(e)}setProps(t){let{backgroundTexture:e}=t;if(e)if(this.setBindings({backgroundTexture:e}),e.isReady){let s=e instanceof Y?e.texture:e;this.backgroundTexture=s,this.updateScale(s)}else e.ready.then(s=>{this.backgroundTexture=s,this.updateScale(s)})}predraw(){super.predraw()}updateScale(t){if(!t){this.shaderInputs.setProps({background:{scale:[1,1]}});return}let[e,s]=this.device.getCanvasContext().getDrawingBufferSize(),r=t.width,n=t.height,o=e/s,a=r/n,c=1,h=1;o>a?h=o/a:c=a/o,this.shaderInputs.setProps({background:{scale:[c,h]}})}};var Mo=1/Math.PI*180,_o=1/180*Math.PI,Xs={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Xs}};var $=globalThis.mathgl.config;function vi(i,{precision:t=$.precision}={}){return i=Hs(i),`${parseFloat(i.toPrecision(t))}`}function vt(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function Pe(i,t,e){let s=$.EPSILON;e&&($.EPSILON=e);try{if(i===t)return!0;if(vt(i)&&vt(t)){if(i.length!==t.length)return!1;for(let r=0;r<i.length;++r)if(!Pe(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)<=$.EPSILON*Math.max(1,Math.abs(i),Math.abs(t)):!1}finally{$.EPSILON=s}}function Hs(i){return Math.round(i/$.EPSILON)*$.EPSILON}var Mt=class extends Array{clone(){return new this.constructor().copy(this)}fromArray(t,e=0){for(let s=0;s<this.ELEMENTS;++s)this[s]=t[s+e];return this.check()}toArray(t=[],e=0){for(let s=0;s<this.ELEMENTS;++s)t[e+s]=this[s];return t}toObject(t){return t}from(t){return Array.isArray(t)?this.copy(t):this.fromObject(t)}to(t){return t===this?this:vt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString($)}formatString(t){let e="";for(let s=0;s<this.ELEMENTS;++s)e+=(s>0?", ":"")+vi(this[s],t);return`${t.printTypes?this.constructor.name:""}[${e}]`}equals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(!Pe(this[e],t[e]))return!1;return!0}exactEquals(t){if(!t||this.length!==t.length)return!1;for(let e=0;e<this.ELEMENTS;++e)if(this[e]!==t[e])return!1;return!0}negate(){for(let t=0;t<this.ELEMENTS;++t)this[t]=-this[t];return this.check()}lerp(t,e,s){if(s===void 0)return this.lerp(this,t,e);for(let r=0;r<this.ELEMENTS;++r){let n=t[r],o=typeof e=="number"?e:e[r];this[r]=n+s*(o-n)}return this.check()}min(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.min(t[e],this[e]);return this.check()}max(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=Math.max(t[e],this[e]);return this.check()}clamp(t,e){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],t[s]),e[s]);return this.check()}add(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]+=e[s];return this.check()}subtract(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]-=e[s];return this.check()}scale(t){if(typeof t=="number")for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;else for(let e=0;e<this.ELEMENTS&&e<t.length;++e)this[e]*=t[e];return this.check()}multiplyByScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}check(){if($.debug&&!this.validate())throw new Error(`math.gl: ${this.constructor.name} some fields set to invalid numbers'`);return this}validate(){let t=this.length===this.ELEMENTS;for(let e=0;e<this.ELEMENTS;++e)t=t&&Number.isFinite(this[e]);return t}sub(t){return this.subtract(t)}setScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]=t;return this.check()}addScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]+=t;return this.check()}subScalar(t){return this.addScalar(-t)}multiplyScalar(t){for(let e=0;e<this.ELEMENTS;++e)this[e]*=t;return this.check()}divideScalar(t){return this.multiplyByScalar(1/t)}clampScalar(t,e){for(let s=0;s<this.ELEMENTS;++s)this[s]=Math.min(Math.max(this[s],t),e);return this.check()}get elements(){return this}};function Ks(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 j(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function Jt(i,t,e=""){if($.debug&&!Ks(i,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return i}function Ee(i,t){if(!i)throw new Error(`math.gl assertion ${t}`)}var te=class extends Mt{get x(){return this[0]}set x(t){this[0]=j(t)}get y(){return this[1]}set y(t){this[1]=j(t)}len(){return Math.sqrt(this.lengthSquared())}magnitude(){return this.len()}lengthSquared(){let t=0;for(let e=0;e<this.ELEMENTS;++e)t+=this[e]*this[e];return t}magnitudeSquared(){return this.lengthSquared()}distance(t){return Math.sqrt(this.distanceSquared(t))}distanceSquared(t){let e=0;for(let s=0;s<this.ELEMENTS;++s){let r=this[s]-t[s];e+=r*r}return j(e)}dot(t){let e=0;for(let s=0;s<this.ELEMENTS;++s)e+=this[s]*t[s];return j(e)}normalize(){let t=this.magnitude();if(t!==0)for(let e=0;e<this.ELEMENTS;++e)this[e]/=t;return this.check()}multiply(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]*=e[s];return this.check()}divide(...t){for(let e of t)for(let s=0;s<this.ELEMENTS;++s)this[s]/=e[s];return this.check()}lengthSq(){return this.lengthSquared()}distanceTo(t){return this.distance(t)}distanceToSquared(t){return this.distanceSquared(t)}getComponent(t){return Ee(t>=0&&t<this.ELEMENTS,"index is out of range"),j(this[t])}setComponent(t,e){return Ee(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 st=typeof Float32Array<"u"?Float32Array:Array;var Oo=Math.PI/180;function Zs(){let i=new st(2);return st!=Float32Array&&(i[0]=0,i[1]=0),i}function wi(i,t,e){let s=t[0],r=t[1];return i[0]=e[0]*s+e[4]*r+e[12],i[1]=e[1]*s+e[5]*r+e[13],i}var ko=function(){let i=Zs();return function(t,e,s,r,n,o){let a,c;for(e||(e=2),s||(s=0),r?c=Math.min(r*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],n(i,i,o),t[a]=i[0],t[a+1]=i[1];return t}}();function Ai(i,t,e){let s=t[0],r=t[1],n=e[3]*s+e[7]*r||1;return i[0]=(e[0]*s+e[4]*r)/n,i[1]=(e[1]*s+e[5]*r)/n,i}function ee(i,t,e){let s=t[0],r=t[1],n=t[2],o=e[3]*s+e[7]*r+e[11]*n||1;return i[0]=(e[0]*s+e[4]*r+e[8]*n)/o,i[1]=(e[1]*s+e[5]*r+e[9]*n)/o,i[2]=(e[2]*s+e[6]*r+e[10]*n)/o,i}function Si(i,t,e){let s=t[0],r=t[1];return i[0]=e[0]*s+e[2]*r,i[1]=e[1]*s+e[3]*r,i[2]=t[2],i}function Qs(){let i=new st(3);return st!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function Js(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]}function Ti(i,t,e){let s=t[0],r=t[1],n=t[2],o=e[0],a=e[1],c=e[2];return i[0]=r*c-n*a,i[1]=n*o-s*c,i[2]=s*a-r*o,i}function ie(i,t,e){let s=t[0],r=t[1],n=t[2],o=e[3]*s+e[7]*r+e[11]*n+e[15];return o=o||1,i[0]=(e[0]*s+e[4]*r+e[8]*n+e[12])/o,i[1]=(e[1]*s+e[5]*r+e[9]*n+e[13])/o,i[2]=(e[2]*s+e[6]*r+e[10]*n+e[14])/o,i}function Ci(i,t,e){let s=t[0],r=t[1],n=t[2];return i[0]=s*e[0]+r*e[3]+n*e[6],i[1]=s*e[1]+r*e[4]+n*e[7],i[2]=s*e[2]+r*e[5]+n*e[8],i}function Ii(i,t,e){let s=e[0],r=e[1],n=e[2],o=e[3],a=t[0],c=t[1],h=t[2],l=r*h-n*c,u=n*a-s*h,d=s*c-r*a,m=r*d-n*u,x=n*l-s*d,f=s*u-r*l,y=o*2;return l*=y,u*=y,d*=y,m*=2,x*=2,f*=2,i[0]=a+l+m,i[1]=c+u+x,i[2]=h+d+f,i}function Pi(i,t,e,s){let r=[],n=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],n[0]=r[0],n[1]=r[1]*Math.cos(s)-r[2]*Math.sin(s),n[2]=r[1]*Math.sin(s)+r[2]*Math.cos(s),i[0]=n[0]+e[0],i[1]=n[1]+e[1],i[2]=n[2]+e[2],i}function Ei(i,t,e,s){let r=[],n=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],n[0]=r[2]*Math.sin(s)+r[0]*Math.cos(s),n[1]=r[1],n[2]=r[2]*Math.cos(s)-r[0]*Math.sin(s),i[0]=n[0]+e[0],i[1]=n[1]+e[1],i[2]=n[2]+e[2],i}function Li(i,t,e,s){let r=[],n=[];return r[0]=t[0]-e[0],r[1]=t[1]-e[1],r[2]=t[2]-e[2],n[0]=r[0]*Math.cos(s)-r[1]*Math.sin(s),n[1]=r[0]*Math.sin(s)+r[1]*Math.cos(s),n[2]=r[2],i[0]=n[0]+e[0],i[1]=n[1]+e[1],i[2]=n[2]+e[2],i}function Ri(i,t){let e=i[0],s=i[1],r=i[2],n=t[0],o=t[1],a=t[2],c=Math.sqrt((e*e+s*s+r*r)*(n*n+o*o+a*a)),h=c&&Js(i,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}var Fo=function(){let i=Qs();return function(t,e,s,r,n,o){let a,c;for(e||(e=3),s||(s=0),r?c=Math.min(r*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],n(i,i,o),t[a]=i[0],t[a+1]=i[1],t[a+2]=i[2];return t}}();var Re=[0,0,0],se,W=class extends te{static get ZERO(){return se||(se=new W(0,0,0),Object.freeze(se)),se}constructor(t=0,e=0,s=0){super(-0,-0,-0),arguments.length===1&&vt(t)?this.copy(t):($.debug&&(j(t),j(e),j(s)),this[0]=t,this[1]=e,this[2]=s)}set(t,e,s){return this[0]=t,this[1]=e,this[2]=s,this.check()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this.check()}fromObject(t){return $.debug&&(j(t.x),j(t.y),j(t.z)),this[0]=t.x,this[1]=t.y,this[2]=t.z,this.check()}toObject(t){return t.x=this[0],t.y=this[1],t.z=this[2],t}get ELEMENTS(){return 3}get z(){return this[2]}set z(t){this[2]=j(t)}angle(t){return Ri(this,t)}cross(t){return Ti(this,this,t),this.check()}rotateX({radians:t,origin:e=Re}){return Pi(this,this,e,t),this.check()}rotateY({radians:t,origin:e=Re}){return Ei(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=Re}){return Li(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return ie(this,this,t),this.check()}transformAsVector(t){return ee(this,this,t),this.check()}transformByMatrix3(t){return Ci(this,this,t),this.check()}transformByMatrix2(t){return Si(this,this,t),this.check()}transformByQuaternion(t){return Ii(this,this,t),this.check()}};var re=class extends Mt{toString(){let t="[";if($.printRowMajor){t+="row-major:";for(let e=0;e<this.RANK;++e)for(let s=0;s<this.RANK;++s)t+=` ${this[s*this.RANK+e]}`}else{t+="column-major:";for(let e=0;e<this.ELEMENTS;++e)t+=` ${this[e]}`}return t+="]",t}getElementIndex(t,e){return e*this.RANK+t}getElement(t,e){return this[e*this.RANK+t]}setElement(t,e,s){return this[e*this.RANK+t]=j(s),this}getColumn(t,e=new Array(this.RANK).fill(-0)){let s=t*this.RANK;for(let r=0;r<this.RANK;++r)e[r]=this[s+r];return e}setColumn(t,e){let s=t*this.RANK;for(let r=0;r<this.RANK;++r)this[s+r]=e[r];return this}};function tr(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 Oi(i,t){if(i===t){let e=t[1],s=t[2],r=t[3],n=t[6],o=t[7],a=t[11];i[1]=t[4],i[2]=t[8],i[3]=t[12],i[4]=e,i[6]=t[9],i[7]=t[13],i[8]=s,i[9]=n,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 ki(i,t){let e=t[0],s=t[1],r=t[2],n=t[3],o=t[4],a=t[5],c=t[6],h=t[7],l=t[8],u=t[9],d=t[10],m=t[11],x=t[12],f=t[13],y=t[14],b=t[15],_=e*a-s*o,p=e*c-r*o,g=e*h-n*o,v=s*c-r*a,M=s*h-n*a,C=r*h-n*c,L=l*f-u*x,P=l*y-d*x,R=l*b-m*x,w=u*y-d*f,S=u*b-m*f,E=d*b-m*y,A=_*E-p*S+g*w+v*R-M*P+C*L;return A?(A=1/A,i[0]=(a*E-c*S+h*w)*A,i[1]=(r*S-s*E-n*w)*A,i[2]=(f*C-y*M+b*v)*A,i[3]=(d*M-u*C-m*v)*A,i[4]=(c*R-o*E-h*P)*A,i[5]=(e*E-r*R+n*P)*A,i[6]=(y*g-x*C-b*p)*A,i[7]=(l*C-d*g+m*p)*A,i[8]=(o*S-a*R+h*L)*A,i[9]=(s*R-e*S-n*L)*A,i[10]=(x*M-f*g+b*_)*A,i[11]=(u*g-l*M-m*_)*A,i[12]=(a*P-o*w-c*L)*A,i[13]=(e*w-s*P+r*L)*A,i[14]=(f*p-x*v-y*_)*A,i[15]=(l*v-u*p+d*_)*A,i):null}function Di(i){let t=i[0],e=i[1],s=i[2],r=i[3],n=i[4],o=i[5],a=i[6],c=i[7],h=i[8],l=i[9],u=i[10],d=i[11],m=i[12],x=i[13],f=i[14],y=i[15],b=t*o-e*n,_=t*a-s*n,p=e*a-s*o,g=h*x-l*m,v=h*f-u*m,M=l*f-u*x,C=t*M-e*v+s*g,L=n*M-o*v+a*g,P=h*p-l*_+u*b,R=m*p-x*_+f*b;return c*C-r*L+y*P-d*R}function Oe(i,t,e){let s=t[0],r=t[1],n=t[2],o=t[3],a=t[4],c=t[5],h=t[6],l=t[7],u=t[8],d=t[9],m=t[10],x=t[11],f=t[12],y=t[13],b=t[14],_=t[15],p=e[0],g=e[1],v=e[2],M=e[3];return i[0]=p*s+g*a+v*u+M*f,i[1]=p*r+g*c+v*d+M*y,i[2]=p*n+g*h+v*m+M*b,i[3]=p*o+g*l+v*x+M*_,p=e[4],g=e[5],v=e[6],M=e[7],i[4]=p*s+g*a+v*u+M*f,i[5]=p*r+g*c+v*d+M*y,i[6]=p*n+g*h+v*m+M*b,i[7]=p*o+g*l+v*x+M*_,p=e[8],g=e[9],v=e[10],M=e[11],i[8]=p*s+g*a+v*u+M*f,i[9]=p*r+g*c+v*d+M*y,i[10]=p*n+g*h+v*m+M*b,i[11]=p*o+g*l+v*x+M*_,p=e[12],g=e[13],v=e[14],M=e[15],i[12]=p*s+g*a+v*u+M*f,i[13]=p*r+g*c+v*d+M*y,i[14]=p*n+g*h+v*m+M*b,i[15]=p*o+g*l+v*x+M*_,i}function Ni(i,t,e){let s=e[0],r=e[1],n=e[2],o,a,c,h,l,u,d,m,x,f,y,b;return t===i?(i[12]=t[0]*s+t[4]*r+t[8]*n+t[12],i[13]=t[1]*s+t[5]*r+t[9]*n+t[13],i[14]=t[2]*s+t[6]*r+t[10]*n+t[14],i[15]=t[3]*s+t[7]*r+t[11]*n+t[15]):(o=t[0],a=t[1],c=t[2],h=t[3],l=t[4],u=t[5],d=t[6],m=t[7],x=t[8],f=t[9],y=t[10],b=t[11],i[0]=o,i[1]=a,i[2]=c,i[3]=h,i[4]=l,i[5]=u,i[6]=d,i[7]=m,i[8]=x,i[9]=f,i[10]=y,i[11]=b,i[12]=o*s+l*r+x*n+t[12],i[13]=a*s+u*r+f*n+t[13],i[14]=c*s+d*r+y*n+t[14],i[15]=h*s+m*r+b*n+t[15]),i}function Fi(i,t,e){let s=e[0],r=e[1],n=e[2];return i[0]=t[0]*s,i[1]=t[1]*s,i[2]=t[2]*s,i[3]=t[3]*s,i[4]=t[4]*r,i[5]=t[5]*r,i[6]=t[6]*r,i[7]=t[7]*r,i[8]=t[8]*n,i[9]=t[9]*n,i[10]=t[10]*n,i[11]=t[11]*n,i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15],i}function zi(i,t,e,s){let r=s[0],n=s[1],o=s[2],a=Math.sqrt(r*r+n*n+o*o),c,h,l,u,d,m,x,f,y,b,_,p,g,v,M,C,L,P,R,w,S,E,A,F;return a<1e-6?null:(a=1/a,r*=a,n*=a,o*=a,h=Math.sin(e),c=Math.cos(e),l=1-c,u=t[0],d=t[1],m=t[2],x=t[3],f=t[4],y=t[5],b=t[6],_=t[7],p=t[8],g=t[9],v=t[10],M=t[11],C=r*r*l+c,L=n*r*l+o*h,P=o*r*l-n*h,R=r*n*l-o*h,w=n*n*l+c,S=o*n*l+r*h,E=r*o*l+n*h,A=n*o*l-r*h,F=o*o*l+c,i[0]=u*C+f*L+p*P,i[1]=d*C+y*L+g*P,i[2]=m*C+b*L+v*P,i[3]=x*C+_*L+M*P,i[4]=u*R+f*w+p*S,i[5]=d*R+y*w+g*S,i[6]=m*R+b*w+v*S,i[7]=x*R+_*w+M*S,i[8]=u*E+f*A+p*F,i[9]=d*E+y*A+g*F,i[10]=m*E+b*A+v*F,i[11]=x*E+_*A+M*F,t!==i&&(i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i)}function $i(i,t,e){let s=Math.sin(e),r=Math.cos(e),n=t[4],o=t[5],a=t[6],c=t[7],h=t[8],l=t[9],u=t[10],d=t[11];return t!==i&&(i[0]=t[0],i[1]=t[1],i[2]=t[2],i[3]=t[3],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[4]=n*r+h*s,i[5]=o*r+l*s,i[6]=a*r+u*s,i[7]=c*r+d*s,i[8]=h*r-n*s,i[9]=l*r-o*s,i[10]=u*r-a*s,i[11]=d*r-c*s,i}function Bi(i,t,e){let s=Math.sin(e),r=Math.cos(e),n=t[0],o=t[1],a=t[2],c=t[3],h=t[8],l=t[9],u=t[10],d=t[11];return t!==i&&(i[4]=t[4],i[5]=t[5],i[6]=t[6],i[7]=t[7],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[0]=n*r-h*s,i[1]=o*r-l*s,i[2]=a*r-u*s,i[3]=c*r-d*s,i[8]=n*s+h*r,i[9]=o*s+l*r,i[10]=a*s+u*r,i[11]=c*s+d*r,i}function Ui(i,t,e){let s=Math.sin(e),r=Math.cos(e),n=t[0],o=t[1],a=t[2],c=t[3],h=t[4],l=t[5],u=t[6],d=t[7];return t!==i&&(i[8]=t[8],i[9]=t[9],i[10]=t[10],i[11]=t[11],i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i[0]=n*r+h*s,i[1]=o*r+l*s,i[2]=a*r+u*s,i[3]=c*r+d*s,i[4]=h*r-n*s,i[5]=l*r-o*s,i[6]=u*r-a*s,i[7]=d*r-c*s,i}function Vi(i,t){let e=t[0],s=t[1],r=t[2],n=t[3],o=e+e,a=s+s,c=r+r,h=e*o,l=s*o,u=s*a,d=r*o,m=r*a,x=r*c,f=n*o,y=n*a,b=n*c;return i[0]=1-u-x,i[1]=l+b,i[2]=d-y,i[3]=0,i[4]=l-b,i[5]=1-h-x,i[6]=m+f,i[7]=0,i[8]=d+y,i[9]=m-f,i[10]=1-h-u,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function ji(i,t,e,s,r,n,o){let a=1/(e-t),c=1/(r-s),h=1/(n-o);return i[0]=n*2*a,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=n*2*c,i[6]=0,i[7]=0,i[8]=(e+t)*a,i[9]=(r+s)*c,i[10]=(o+n)*h,i[11]=-1,i[12]=0,i[13]=0,i[14]=o*n*2*h,i[15]=0,i}function er(i,t,e,s,r){let n=1/Math.tan(t/2);if(i[0]=n/e,i[1]=0,i[2]=0,i[3]=0,i[4]=0,i[5]=n,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/(s-r);i[10]=(r+s)*o,i[14]=2*r*s*o}else i[10]=-1,i[14]=-2*s;return i}var Gi=er;function ir(i,t,e,s,r,n,o){let a=1/(t-e),c=1/(s-r),h=1/(n-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+s)*c,i[14]=(o+n)*h,i[15]=1,i}var Wi=ir;function qi(i,t,e,s){let r,n,o,a,c,h,l,u,d,m,x=t[0],f=t[1],y=t[2],b=s[0],_=s[1],p=s[2],g=e[0],v=e[1],M=e[2];return Math.abs(x-g)<1e-6&&Math.abs(f-v)<1e-6&&Math.abs(y-M)<1e-6?tr(i):(u=x-g,d=f-v,m=y-M,r=1/Math.sqrt(u*u+d*d+m*m),u*=r,d*=r,m*=r,n=_*m-p*d,o=p*u-b*m,a=b*d-_*u,r=Math.sqrt(n*n+o*o+a*a),r?(r=1/r,n*=r,o*=r,a*=r):(n=0,o=0,a=0),c=d*a-m*o,h=m*n-u*a,l=u*o-d*n,r=Math.sqrt(c*c+h*h+l*l),r?(r=1/r,c*=r,h*=r,l*=r):(c=0,h=0,l=0),i[0]=n,i[1]=c,i[2]=u,i[3]=0,i[4]=o,i[5]=h,i[6]=d,i[7]=0,i[8]=a,i[9]=l,i[10]=m,i[11]=0,i[12]=-(n*x+o*f+a*y),i[13]=-(c*x+h*f+l*y),i[14]=-(u*x+d*f+m*y),i[15]=1,i)}function sr(){let i=new st(4);return st!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function Yi(i,t,e){let s=t[0],r=t[1],n=t[2],o=t[3];return i[0]=e[0]*s+e[4]*r+e[8]*n+e[12]*o,i[1]=e[1]*s+e[5]*r+e[9]*n+e[13]*o,i[2]=e[2]*s+e[6]*r+e[10]*n+e[14]*o,i[3]=e[3]*s+e[7]*r+e[11]*n+e[15]*o,i}var Ko=function(){let i=sr();return function(t,e,s,r,n,o){let a,c;for(e||(e=4),s||(s=0),r?c=Math.min(r*e+s,t.length):c=t.length,a=s;a<c;a+=e)i[0]=t[a],i[1]=t[a+1],i[2]=t[a+2],i[3]=t[a+3],n(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 Ne;(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"})(Ne||(Ne={}));var rr=45*Math.PI/180,nr=1,ke=.1,De=500,or=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),K=class extends re{static get IDENTITY(){return cr()}static get ZERO(){return ar()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return Ne}constructor(t){super(-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0),arguments.length===1&&Array.isArray(t)?this.copy(t):this.identity()}copy(t){return this[0]=t[0],this[1]=t[1],this[2]=t[2],this[3]=t[3],this[4]=t[4],this[5]=t[5],this[6]=t[6],this[7]=t[7],this[8]=t[8],this[9]=t[9],this[10]=t[10],this[11]=t[11],this[12]=t[12],this[13]=t[13],this[14]=t[14],this[15]=t[15],this.check()}set(t,e,s,r,n,o,a,c,h,l,u,d,m,x,f,y){return this[0]=t,this[1]=e,this[2]=s,this[3]=r,this[4]=n,this[5]=o,this[6]=a,this[7]=c,this[8]=h,this[9]=l,this[10]=u,this[11]=d,this[12]=m,this[13]=x,this[14]=f,this[15]=y,this.check()}setRowMajor(t,e,s,r,n,o,a,c,h,l,u,d,m,x,f,y){return this[0]=t,this[1]=n,this[2]=h,this[3]=m,this[4]=e,this[5]=o,this[6]=l,this[7]=x,this[8]=s,this[9]=a,this[10]=u,this[11]=f,this[12]=r,this[13]=c,this[14]=d,this[15]=y,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(or)}fromObject(t){return this.check()}fromQuaternion(t){return Vi(this,t),this.check()}frustum(t){let{left:e,right:s,bottom:r,top:n,near:o=ke,far:a=De}=t;return a===1/0?hr(this,e,s,r,n,o):ji(this,e,s,r,n,o,a),this.check()}lookAt(t){let{eye:e,center:s=[0,0,0],up:r=[0,1,0]}=t;return qi(this,e,s,r),this.check()}ortho(t){let{left:e,right:s,bottom:r,top:n,near:o=ke,far:a=De}=t;return Wi(this,e,s,r,n,o,a),this.check()}orthographic(t){let{fovy:e=rr,aspect:s=nr,focalDistance:r=1,near:n=ke,far:o=De}=t;Xi(e);let a=e/2,c=r*Math.tan(a),h=c*s;return this.ortho({left:-h,right:h,bottom:-c,top:c,near:n,far:o})}perspective(t){let{fovy:e=45*Math.PI/180,aspect:s=1,near:r=.1,far:n=500}=t;return Xi(e),Gi(this,e,s,r,n),this.check()}determinant(){return Di(this)}getScale(t=[-0,-0,-0]){return t[0]=Math.sqrt(this[0]*this[0]+this[1]*this[1]+this[2]*this[2]),t[1]=Math.sqrt(this[4]*this[4]+this[5]*this[5]+this[6]*this[6]),t[2]=Math.sqrt(this[8]*this[8]+this[9]*this[9]+this[10]*this[10]),t}getTranslation(t=[-0,-0,-0]){return t[0]=this[12],t[1]=this[13],t[2]=this[14],t}getRotation(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let s=this.getScale(e),r=1/s[0],n=1/s[1],o=1/s[2];return t[0]=this[0]*r,t[1]=this[1]*n,t[2]=this[2]*o,t[3]=0,t[4]=this[4]*r,t[5]=this[5]*n,t[6]=this[6]*o,t[7]=0,t[8]=this[8]*r,t[9]=this[9]*n,t[10]=this[10]*o,t[11]=0,t[12]=0,t[13]=0,t[14]=0,t[15]=1,t}getRotationMatrix3(t,e){t=t||[-0,-0,-0,-0,-0,-0,-0,-0,-0],e=e||[-0,-0,-0];let s=this.getScale(e),r=1/s[0],n=1/s[1],o=1/s[2];return t[0]=this[0]*r,t[1]=this[1]*n,t[2]=this[2]*o,t[3]=this[4]*r,t[4]=this[5]*n,t[5]=this[6]*o,t[6]=this[8]*r,t[7]=this[9]*n,t[8]=this[10]*o,t}transpose(){return Oi(this,this),this.check()}invert(){return ki(this,this),this.check()}multiplyLeft(t){return Oe(this,t,this),this.check()}multiplyRight(t){return Oe(this,this,t),this.check()}rotateX(t){return $i(this,this,t),this.check()}rotateY(t){return Bi(this,this,t),this.check()}rotateZ(t){return Ui(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return zi(this,this,t,e),this.check()}scale(t){return Fi(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return Ni(this,this,t),this.check()}transform(t,e){return t.length===4?(e=Yi(e||[-0,-0,-0,-0],t,this),Jt(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:s}=t,r;switch(s){case 2:r=wi(e||[-0,-0],t,this);break;case 3:r=ie(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Jt(r,t.length),r}transformAsVector(t,e){let s;switch(t.length){case 2:s=Ai(e||[-0,-0],t,this);break;case 3:s=ee(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return Jt(s,t.length),s}transformPoint(t,e){return this.transformAsPoint(t,e)}transformVector(t,e){return this.transformAsPoint(t,e)}transformDirection(t,e){return this.transformAsVector(t,e)}makeRotationX(t){return this.identity().rotateX(t)}makeTranslation(t,e,s){return this.identity().translate([t,e,s])}},ne,oe;function ar(){return ne||(ne=new K([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(ne)),ne}function cr(){return oe||(oe=new K,Object.freeze(oe)),oe}function Xi(i){if(i>Math.PI*2)throw Error("expected radians")}function hr(i,t,e,s,r,n){let o=2*n/(e-t),a=2*n/(r-s),c=(e+t)/(e-t),h=(r+s)/(r-s),l=-1,u=-1,d=-2*n;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]=u,i[12]=0,i[13]=0,i[14]=d,i[15]=0,i}var rt=class{id;matrix=new K;display=!0;position=new W;rotation=new W;scale=new W(1,1,1);userData={};props={};constructor(t={}){let{id:e}=t;this.id=e||I(this.constructor.name),this._setScenegraphNodeProps(t)}getBounds(){return null}destroy(){}delete(){this.destroy()}setProps(t){return this._setScenegraphNodeProps(t),this}toString(){return`{type: ScenegraphNode, id: ${this.id})}`}setPosition(t){return this.position=t,this}setRotation(t){return this.rotation=t,this}setScale(t){return this.scale=t,this}setMatrix(t,e=!0){e?this.matrix.copy(t):this.matrix=t}setMatrixComponents(t){let{position:e,rotation:s,scale:r,update:n=!0}=t;return e&&this.setPosition(e),s&&this.setRotation(s),r&&this.setScale(r),n&&this.updateMatrix(),this}updateMatrix(){let t=this.position,e=this.rotation,s=this.scale;return this.matrix.identity(),this.matrix.translate(t),this.matrix.rotateXYZ(e),this.matrix.scale(s),this}update(t={}){let{position:e,rotation:s,scale:r}=t;return e&&this.setPosition(e),s&&this.setRotation(s),r&&this.setScale(r),this.updateMatrix(),this}getCoordinateUniforms(t,e){e=e||this.matrix;let s=new K(t).multiplyRight(e),r=s.invert(),n=r.transpose();return{viewMatrix:t,modelMatrix:e,objectMatrix:e,worldMatrix:s,worldInverseMatrix:r,worldInverseTransposeMatrix:n}}_setScenegraphNodeProps(t){"position"in t&&this.setPosition(t.position),"rotation"in t&&this.setRotation(t.rotation),"scale"in t&&this.setScale(t.scale),"matrix"in t&&this.setMatrix(t.matrix),Object.assign(this.props,t)}};var Hi=O(z(),1);var wt=class extends rt{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;Hi.log.assert(e.every(s=>s instanceof rt),"every child must an instance of ScenegraphNode"),super(t),this.children=e}getBounds(){let t=[[1/0,1/0,1/0],[-1/0,-1/0,-1/0]];return this.traverse((e,{worldMatrix:s})=>{let r=e.getBounds();if(!r)return;let[n,o]=r,a=new W(n).add(o).divide([2,2,2]);s.transformAsPoint(a,a);let c=new W(o).subtract(n).divide([2,2,2]);s.transformAsVector(c,c);for(let h=0;h<8;h++){let l=new W(h&1?-1:1,h&2?-1:1,h&4?-1:1).multiply(c).add(a);for(let u=0;u<3;u++)t[0][u]=Math.min(t[0][u],l[u]),t[1][u]=Math.max(t[1][u],l[u])}}),Number.isFinite(t[0][0])?t:null}destroy(){this.children.forEach(t=>t.destroy()),this.removeAll(),super.destroy()}add(...t){for(let e of t)Array.isArray(e)?this.add(...e):this.children.push(e);return this}remove(t){let e=this.children,s=e.indexOf(t);return s>-1&&e.splice(s,1),this}removeAll(){return this.children=[],this}traverse(t,{worldMatrix:e=new K}={}){let s=new K(e).multiplyRight(this.matrix);for(let r of this.children)r instanceof wt?r.traverse(t,{worldMatrix:s}):t(r,{worldMatrix:s})}};var ae=class extends rt{model;bounds=null;managedResources;constructor(t){super(t),this.model=t.model,this.managedResources=t.managedResources||[],this.bounds=t.bounds||null,this.setProps(t)}destroy(){this.model&&(this.model.destroy(),this.model=null),this.managedResources.forEach(t=>t.destroy()),this.managedResources=[]}getBounds(){return this.bounds}draw(t){return this.model.draw(t)}};var lr={x:[2,0,1],y:[0,1,2],z:[1,2,0]},ot=class extends V{constructor(t={}){let{id:e=I("truncated-code-geometry")}=t,{indices:s,attributes:r}=ur(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{POSITION:{size:3,value:r.POSITION},NORMAL:{size:3,value:r.NORMAL},TEXCOORD_0:{size:2,value:r.TEXCOORD_0},...t.attributes}})}};function ur(i={}){let{bottomRadius:t=0,topRadius:e=0,height:s=1,nradial:r=10,nvertical:n=10,verticalAxis:o="y",topCap:a=!1,bottomCap:c=!1}=i,h=(a?2:0)+(c?2:0),l=(r+1)*(n+1+h),u=Math.atan2(t-e,s),d=Math.sin,m=Math.cos,x=Math.PI,f=m(u),y=d(u),b=a?-2:0,_=n+(c?2:0),p=r+1,g=new Uint16Array(r*(n+h)*6),v=lr[o],M=new Float32Array(l*3),C=new Float32Array(l*3),L=new Float32Array(l*2),P=0,R=0;for(let w=b;w<=_;w++){let S=w/n,E=s*S,A;w<0?(E=0,S=1,A=t):w>n?(E=s,S=1,A=e):A=t+(e-t)*(w/n),(w===-2||w===n+2)&&(A=0,S=0),E-=s/2;for(let F=0;F<p;F++){let J=d(F*x*2/r),H=m(F*x*2/r);M[P+v[0]]=J*A,M[P+v[1]]=E,M[P+v[2]]=H*A,C[P+v[0]]=w<0||w>n?0:J*f,C[P+v[1]]=w<0?-1:w>n?1:y,C[P+v[2]]=w<0||w>n?0:H*f,L[R+0]=F/r,L[R+1]=S,R+=2,P+=3}}for(let w=0;w<n+h;w++)for(let S=0;S<r;S++){let E=(w*r+S)*6;g[E+0]=p*(w+0)+0+S,g[E+1]=p*(w+0)+1+S,g[E+2]=p*(w+1)+1+S,g[E+3]=p*(w+0)+0+S,g[E+4]=p*(w+1)+1+S,g[E+5]=p*(w+1)+0+S}return{indices:g,attributes:{POSITION:M,NORMAL:C,TEXCOORD_0:L}}}var ce=class extends ot{constructor(t={}){let{id:e=I("cone-geometry"),radius:s=1,cap:r=!0}=t;super({...t,id:e,topRadius:0,topCap:Boolean(r),bottomCap:Boolean(r),bottomRadius:s})}};var he=class extends V{constructor(t={}){let{id:e=I("cube-geometry"),indices:s=!0}=t;super(s?{...t,id:e,topology:"triangle-list",indices:{size:1,value:dr},attributes:{...br,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...vr,...t.attributes}})}},dr=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]),fr=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]),pr=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]),mr=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]),gr=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]),xr=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]),yr=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]),br={POSITION:{size:3,value:fr},NORMAL:{size:3,value:pr},TEXCOORD_0:{size:2,value:mr}},vr={POSITION:{size:3,value:gr},TEXCOORD_0:{size:2,value:xr},COLOR_0:{size:3,value:yr}};var le=class extends ot{constructor(t={}){let{id:e=I("cylinder-geometry"),radius:s=1}=t;super({...t,id:e,bottomRadius:s,topRadius:s})}};var Mr=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],_r=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],ue=class extends V{constructor(t={}){let{id:e=I("ico-sphere-geometry")}=t,{indices:s,attributes:r}=wr(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...r,...t.attributes}})}};function wr(i){let{iterations:t=0}=i,e=Math.PI,s=e*2,r=[...Mr],n=[..._r];r.push(),n.push();let o=(()=>{let l={};return(u,d)=>{u*=3,d*=3;let m=u<d?u:d,x=u>d?u:d,f=`${m}|${x}`;if(f in l)return l[f];let y=r[u],b=r[u+1],_=r[u+2],p=r[d],g=r[d+1],v=r[d+2],M=(y+p)/2,C=(b+g)/2,L=(_+v)/2,P=Math.sqrt(M*M+C*C+L*L);return M/=P,C/=P,L/=P,r.push(M,C,L),l[f]=r.length/3-1}})();for(let l=0;l<t;l++){let u=[];for(let d=0;d<n.length;d+=3){let m=o(n[d+0],n[d+1]),x=o(n[d+1],n[d+2]),f=o(n[d+2],n[d+0]);u.push(f,n[d+0],m,m,n[d+1],x,x,n[d+2],f,m,x,f)}n=u}let a=new Array(r.length),c=new Array(r.length/3*2),h=n.length;for(let l=h-3;l>=0;l-=3){let u=n[l+0],d=n[l+1],m=n[l+2],x=u*3,f=d*3,y=m*3,b=u*2,_=d*2,p=m*2,g=r[x+0],v=r[x+1],M=r[x+2],C=Math.acos(M/Math.sqrt(g*g+v*v+M*M)),L=Math.atan2(v,g)+e,P=C/e,R=1-L/s,w=r[f+0],S=r[f+1],E=r[f+2],A=Math.acos(E/Math.sqrt(w*w+S*S+E*E)),F=Math.atan2(S,w)+e,J=A/e,H=1-F/s,Ft=r[y+0],zt=r[y+1],$t=r[y+2],ns=Math.acos($t/Math.sqrt(Ft*Ft+zt*zt+$t*$t)),os=Math.atan2(zt,Ft)+e,Ue=ns/e,Bt=1-os/s,as=[Ft-w,zt-S,$t-E],cs=[g-w,v-S,M-E],X=new W(as).cross(cs).normalize(),k;(R===0||H===0||Bt===0)&&(R===0||R>.5)&&(H===0||H>.5)&&(Bt===0||Bt>.5)&&(r.push(r[x+0],r[x+1],r[x+2]),k=r.length/3-1,n.push(k),c[k*2+0]=1,c[k*2+1]=P,a[k*3+0]=X.x,a[k*3+1]=X.y,a[k*3+2]=X.z,r.push(r[f+0],r[f+1],r[f+2]),k=r.length/3-1,n.push(k),c[k*2+0]=1,c[k*2+1]=J,a[k*3+0]=X.x,a[k*3+1]=X.y,a[k*3+2]=X.z,r.push(r[y+0],r[y+1],r[y+2]),k=r.length/3-1,n.push(k),c[k*2+0]=1,c[k*2+1]=Ue,a[k*3+0]=X.x,a[k*3+1]=X.y,a[k*3+2]=X.z),a[x+0]=a[f+0]=a[y+0]=X.x,a[x+1]=a[f+1]=a[y+1]=X.y,a[x+2]=a[f+2]=a[y+2]=X.z,c[b+0]=R,c[b+1]=P,c[_+0]=H,c[_+1]=J,c[p+0]=Bt,c[p+1]=Ue}return{indices:{size:1,value:new Uint16Array(n)},attributes:{POSITION:{size:3,value:new Float32Array(r)},NORMAL:{size:3,value:new Float32Array(a)},TEXCOORD_0:{size:2,value:new Float32Array(c)}}}}function Ki(i){let{indices:t,attributes:e}=i;if(!t)return i;let s=t.value.length,r={};for(let n in e){let o=e[n],{constant:a,value:c,size:h}=o;if(a||!h)continue;let l=new c.constructor(s*h);for(let u=0;u<s;++u){let d=t.value[u];for(let m=0;m<h;m++)l[u*h+m]=c[d*h+m]}r[n]={size:h,value:l}}return{attributes:Object.assign({},e,r)}}var de=class extends V{constructor(t={}){let{id:e=I("plane-geometry")}=t,{indices:s,attributes:r}=Ar(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...r,...t.attributes}})}};function Ar(i){let{type:t="x,y",offset:e=0,flipCull:s=!1,unpack:r=!1}=i,n=t.split(","),o=i[`${n[0]}len`]||1,a=i[`${n[1]}len`]||1,c=i[`n${n[0]}`]||1,h=i[`n${n[1]}`]||1,l=(c+1)*(h+1),u=new Float32Array(l*3),d=new Float32Array(l*3),m=new Float32Array(l*2);s&&(o=-o);let x=0,f=0;for(let p=0;p<=h;p++)for(let g=0;g<=c;g++){let v=g/c,M=p/h;switch(m[x+0]=s?1-v:v,m[x+1]=M,t){case"x,y":u[f+0]=o*v-o*.5,u[f+1]=a*M-a*.5,u[f+2]=e,d[f+0]=0,d[f+1]=0,d[f+2]=s?1:-1;break;case"x,z":u[f+0]=o*v-o*.5,u[f+1]=e,u[f+2]=a*M-a*.5,d[f+0]=0,d[f+1]=s?1:-1,d[f+2]=0;break;case"y,z":u[f+0]=e,u[f+1]=o*v-o*.5,u[f+2]=a*M-a*.5,d[f+0]=s?1:-1,d[f+1]=0,d[f+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}x+=2,f+=3}let y=c+1,b=new Uint16Array(c*h*6);for(let p=0;p<h;p++)for(let g=0;g<c;g++){let v=(p*c+g)*6;b[v+0]=(p+0)*y+g,b[v+1]=(p+1)*y+g,b[v+2]=(p+0)*y+g+1,b[v+3]=(p+1)*y+g,b[v+4]=(p+1)*y+g+1,b[v+5]=(p+0)*y+g+1}let _={indices:{size:1,value:b},attributes:{POSITION:{size:3,value:u},NORMAL:{size:3,value:d},TEXCOORD_0:{size:2,value:m}}};return r?Ki(_):_}var fe=class extends V{constructor(t={}){let{id:e=I("sphere-geometry")}=t,{indices:s,attributes:r}=Sr(t);super({...t,id:e,topology:"triangle-list",indices:s,attributes:{...r,...t.attributes}})}};function Sr(i){let{nlat:t=10,nlong:e=10}=i,n=Math.PI-0,o=0,c=2*Math.PI-o,h=(t+1)*(e+1),l=(b,_,p,g,v)=>i.radius||1,u=new Float32Array(h*3),d=new Float32Array(h*3),m=new Float32Array(h*2),x=h>65535?Uint32Array:Uint16Array,f=new x(t*e*6);for(let b=0;b<=t;b++)for(let _=0;_<=e;_++){let p=_/e,g=b/t,v=_+b*(e+1),M=v*2,C=v*3,L=c*p,P=n*g,R=Math.sin(L),w=Math.cos(L),S=Math.sin(P),E=Math.cos(P),A=w*S,F=E,J=R*S,H=l(A,F,J,p,g);u[C+0]=H*A,u[C+1]=H*F,u[C+2]=H*J,d[C+0]=A,d[C+1]=F,d[C+2]=J,m[M+0]=p,m[M+1]=1-g}let y=e+1;for(let b=0;b<e;b++)for(let _=0;_<t;_++){let p=(b*t+_)*6;f[p+0]=_*y+b,f[p+1]=_*y+b+1,f[p+2]=(_+1)*y+b,f[p+3]=(_+1)*y+b,f[p+4]=_*y+b+1,f[p+5]=(_+1)*y+b+1}return{indices:{size:1,value:f},attributes:{POSITION:{size:3,value:u},NORMAL:{size:3,value:d},TEXCOORD_0:{size:2,value:m}}}}function Zi(){let i=1,t=1;return()=>(i=Math.sin(t*17.23),t=Math.cos(i*27.92),Tr(Math.abs(i*t)*1432.71))}function Tr(i){return i-Math.floor(i)}var Fe="";function Qi(i){Fe=i}async function Ji(i,t){let e=new Image;return e.crossOrigin=t?.crossOrigin||"anonymous",e.src=i.startsWith("http")?i:Fe+i,await e.decode(),t?await createImageBitmap(e,t):await createImageBitmap(e)}async function ts(i,t){return await new Promise((e,s)=>{try{let r=new Image;r.onload=()=>e(r),r.onerror=()=>s(new Error(`Could not load image ${i}.`)),r.crossOrigin=t?.crossOrigin||"anonymous",r.src=i.startsWith("http")?i:Fe+i}catch(r){s(r)}})}var is=O(ht(),1);var nt=O(z(),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}},St=class extends At{constructor(t,e){e={...e};let{width:s=1,height:r=1}=e,n=e.colorAttachments?.map(c=>typeof c!="string"?c:t.createTexture({id:`${e.id}-texture-0`,format:c,usage:nt.Texture.SAMPLE|nt.Texture.RENDER|nt.Texture.COPY_SRC|nt.Texture.COPY_DST,width:s,height:r})),o=t.createFramebuffer({...e,colorAttachments:n});n=e.colorAttachments?.map(c=>typeof c!="string"?c:t.createTexture({id:`${e.id}-texture-1`,format:c,usage:nt.Texture.SAMPLE|nt.Texture.RENDER|nt.Texture.COPY_SRC|nt.Texture.COPY_DST,width:s,height:r}));let a=t.createFramebuffer({...e,colorAttachments:n});super({current:o,next:a})}resize(t){if(t.width===this.current.width&&t.height===this.current.height)return!1;let{current:e,next:s}=this;return this.current=e.clone(t),e.destroy(),this.next=s.clone(t),s.destroy(),!0}},pe=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:s}=this;return this.current=e.clone(t),e.destroy(),this.next=s.clone(t),s.destroy(),!0}};function es(i){let{shaderPass:t,action:e,shadingLanguage:s}=i;switch(e){case"filter":let r=`${t.name}_filterColor_ext`;return s==="wgsl"?Cr(r):Pr(r);case"sample":let n=`${t.name}_sampleColor`;return s==="wgsl"?Ir(n):Er(n);default:throw new Error(`${t.name} no fragment shader generated for shader pass`)}}function Cr(i){return`// Binding 0:1 is reserved for shader passes
|
|
244
|
-
|
|
245
|
-
|
|
246
|
-
|
|
84
|
+
`,_t=class extends st{backgroundTexture=null;constructor(t,e){if(super(t,{...e,id:e.id||"background-texture-model",source:Sr,fs:Lr,modules:[...e.modules||[],Pr],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 z?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 It=class extends V{constructor(t={}){let{id:e=S("sphere-geometry")}=t,{indices:n,attributes:r}=Cr(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Cr(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,b)=>i.radius||1,d=new Float32Array(h*3),u=new Float32Array(h*3),g=new Float32Array(h*2),p=h>65535?Uint32Array:Uint16Array,f=new p(t*e*6);for(let M=0;M<=t;M++)for(let I=0;I<=e;I++){let m=I/e,x=M/t,b=I+M*(e+1),_=b*2,T=b*3,E=c*m,L=s*x,O=Math.sin(E),v=Math.cos(E),P=Math.sin(L),C=Math.cos(L),A=v*P,B=C,tt=O*P,Z=l(A,B,tt,m,x);d[T+0]=Z*A,d[T+1]=Z*B,d[T+2]=Z*tt,u[T+0]=A,u[T+1]=B,u[T+2]=tt,g[_+0]=m,g[_+1]=1-x}let y=e+1;for(let M=0;M<e;M++)for(let I=0;I<t;I++){let m=(M*t+I)*6;f[m+0]=I*y+M,f[m+1]=I*y+M+1,f[m+2]=(I+1)*y+M,f[m+3]=(I+1)*y+M,f[m+4]=I*y+M+1,f[m+5]=(I+1)*y+M+1}return{indices:{size:1,value:f},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:u},TEXCOORD_0:{size:2,value:g}}}}var wa=1/Math.PI*180,Aa=1/180*Math.PI,Er={EPSILON:1e-12,debug:!1,precision:4,printTypes:!1,printDegrees:!1,printRowMajor:!0,_cartographicRadians:!1};globalThis.mathgl=globalThis.mathgl||{config:{...Er}};var j=globalThis.mathgl.config;function Gi(i,{precision:t=j.precision}={}){return i=Or(i),`${parseFloat(i.toPrecision(t))}`}function vt(i){return Array.isArray(i)||ArrayBuffer.isView(i)&&!(i instanceof DataView)}function He(i,t,e){let n=j.EPSILON;e&&(j.EPSILON=e);try{if(i===t)return!0;if(vt(i)&&vt(t)){if(i.length!==t.length)return!1;for(let r=0;r<i.length;++r)if(!He(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)<=j.EPSILON*Math.max(1,Math.abs(i),Math.abs(t)):!1}finally{j.EPSILON=n}}function Or(i){return Math.round(i/j.EPSILON)*j.EPSILON}var wt=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:vt(t)?this.toArray(t):this.toObject(t)}toTarget(t){return t?this.to(t):this}toFloat32Array(){return new Float32Array(this)}toString(){return this.formatString(j)}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(!He(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(j.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 kr(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 X(i){if(!Number.isFinite(i))throw new Error(`Invalid number ${JSON.stringify(i)}`);return i}function oe(i,t,e=""){if(j.debug&&!kr(i,t))throw new Error(`math.gl: ${e} some fields set to invalid numbers'`);return i}function We(i,t){if(!i)throw new Error(`math.gl assertion ${t}`)}var ae=class extends wt{get x(){return this[0]}set x(t){this[0]=X(t)}get y(){return this[1]}set y(t){this[1]=X(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 X(e)}dot(t){let e=0;for(let n=0;n<this.ELEMENTS;++n)e+=this[n]*t[n];return X(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 We(t>=0&&t<this.ELEMENTS,"index is out of range"),X(this[t])}setComponent(t,e){return We(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 et=typeof Float32Array<"u"?Float32Array:Array;var Da=Math.PI/180;function Rr(){let i=new et(2);return et!=Float32Array&&(i[0]=0,i[1]=0),i}function Vi(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 Fa=function(){let i=Rr();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 Xi(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 ce(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 qi(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 Nr(){let i=new et(3);return et!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0),i}function Dr(i,t){return i[0]*t[0]+i[1]*t[1]+i[2]*t[2]}function Hi(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 he(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 Wi(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 Yi(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,u=n*c-r*a,g=r*u-s*d,p=s*l-n*u,f=n*d-r*l,y=o*2;return l*=y,d*=y,u*=y,g*=2,p*=2,f*=2,i[0]=a+l+g,i[1]=c+d+p,i[2]=h+u+f,i}function Ki(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 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[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 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[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 Ji(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&&Dr(i,t)/c;return Math.acos(Math.min(Math.max(h,-1),1))}var ja=function(){let i=Nr();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 Ke=[0,0,0],le,H=class extends ae{static get ZERO(){return le||(le=new H(0,0,0),Object.freeze(le)),le}constructor(t=0,e=0,n=0){super(-0,-0,-0),arguments.length===1&&vt(t)?this.copy(t):(j.debug&&(X(t),X(e),X(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 j.debug&&(X(t.x),X(t.y),X(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]=X(t)}angle(t){return Ji(this,t)}cross(t){return Hi(this,this,t),this.check()}rotateX({radians:t,origin:e=Ke}){return Ki(this,this,e,t),this.check()}rotateY({radians:t,origin:e=Ke}){return Zi(this,this,e,t),this.check()}rotateZ({radians:t,origin:e=Ke}){return Qi(this,this,e,t),this.check()}transform(t){return this.transformAsPoint(t)}transformAsPoint(t){return he(this,this,t),this.check()}transformAsVector(t){return ce(this,this,t),this.check()}transformByMatrix3(t){return Wi(this,this,t),this.check()}transformByMatrix2(t){return qi(this,this,t),this.check()}transformByQuaternion(t){return Yi(this,this,t),this.check()}};var de=class extends wt{toString(){let t="[";if(j.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]=X(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 Fr(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 tn(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 en(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],u=t[10],g=t[11],p=t[12],f=t[13],y=t[14],M=t[15],I=e*a-n*o,m=e*c-r*o,x=e*h-s*o,b=n*c-r*a,_=n*h-s*a,T=r*h-s*c,E=l*f-d*p,L=l*y-u*p,O=l*M-g*p,v=d*y-u*f,P=d*M-g*f,C=u*M-g*y,A=I*C-m*P+x*v+b*O-_*L+T*E;return A?(A=1/A,i[0]=(a*C-c*P+h*v)*A,i[1]=(r*P-n*C-s*v)*A,i[2]=(f*T-y*_+M*b)*A,i[3]=(u*_-d*T-g*b)*A,i[4]=(c*O-o*C-h*L)*A,i[5]=(e*C-r*O+s*L)*A,i[6]=(y*x-p*T-M*m)*A,i[7]=(l*T-u*x+g*m)*A,i[8]=(o*P-a*O+h*E)*A,i[9]=(n*O-e*P-s*E)*A,i[10]=(p*_-f*x+M*I)*A,i[11]=(d*x-l*_-g*I)*A,i[12]=(a*L-o*v-c*E)*A,i[13]=(e*v-n*L+r*E)*A,i[14]=(f*m-p*b-y*I)*A,i[15]=(l*b-d*m+u*I)*A,i):null}function nn(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],u=i[11],g=i[12],p=i[13],f=i[14],y=i[15],M=t*o-e*s,I=t*a-n*s,m=e*a-n*o,x=h*p-l*g,b=h*f-d*g,_=l*f-d*p,T=t*_-e*b+n*x,E=s*_-o*b+a*x,L=h*m-l*I+d*M,O=g*m-p*I+f*M;return c*T-r*E+y*L-u*O}function Ze(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],u=t[9],g=t[10],p=t[11],f=t[12],y=t[13],M=t[14],I=t[15],m=e[0],x=e[1],b=e[2],_=e[3];return i[0]=m*n+x*a+b*d+_*f,i[1]=m*r+x*c+b*u+_*y,i[2]=m*s+x*h+b*g+_*M,i[3]=m*o+x*l+b*p+_*I,m=e[4],x=e[5],b=e[6],_=e[7],i[4]=m*n+x*a+b*d+_*f,i[5]=m*r+x*c+b*u+_*y,i[6]=m*s+x*h+b*g+_*M,i[7]=m*o+x*l+b*p+_*I,m=e[8],x=e[9],b=e[10],_=e[11],i[8]=m*n+x*a+b*d+_*f,i[9]=m*r+x*c+b*u+_*y,i[10]=m*s+x*h+b*g+_*M,i[11]=m*o+x*l+b*p+_*I,m=e[12],x=e[13],b=e[14],_=e[15],i[12]=m*n+x*a+b*d+_*f,i[13]=m*r+x*c+b*u+_*y,i[14]=m*s+x*h+b*g+_*M,i[15]=m*o+x*l+b*p+_*I,i}function rn(i,t,e){let n=e[0],r=e[1],s=e[2],o,a,c,h,l,d,u,g,p,f,y,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],u=t[6],g=t[7],p=t[8],f=t[9],y=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]=u,i[7]=g,i[8]=p,i[9]=f,i[10]=y,i[11]=M,i[12]=o*n+l*r+p*s+t[12],i[13]=a*n+d*r+f*s+t[13],i[14]=c*n+u*r+y*s+t[14],i[15]=h*n+g*r+M*s+t[15]),i}function sn(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 on(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,u,g,p,f,y,M,I,m,x,b,_,T,E,L,O,v,P,C,A,B;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],u=t[1],g=t[2],p=t[3],f=t[4],y=t[5],M=t[6],I=t[7],m=t[8],x=t[9],b=t[10],_=t[11],T=r*r*l+c,E=s*r*l+o*h,L=o*r*l-s*h,O=r*s*l-o*h,v=s*s*l+c,P=o*s*l+r*h,C=r*o*l+s*h,A=s*o*l-r*h,B=o*o*l+c,i[0]=d*T+f*E+m*L,i[1]=u*T+y*E+x*L,i[2]=g*T+M*E+b*L,i[3]=p*T+I*E+_*L,i[4]=d*O+f*v+m*P,i[5]=u*O+y*v+x*P,i[6]=g*O+M*v+b*P,i[7]=p*O+I*v+_*P,i[8]=d*C+f*A+m*B,i[9]=u*C+y*A+x*B,i[10]=g*C+M*A+b*B,i[11]=p*C+I*A+_*B,t!==i&&(i[12]=t[12],i[13]=t[13],i[14]=t[14],i[15]=t[15]),i)}function an(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],u=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+u*n,i[8]=h*r-s*n,i[9]=l*r-o*n,i[10]=d*r-a*n,i[11]=u*r-c*n,i}function cn(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],u=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-u*n,i[8]=s*n+h*r,i[9]=o*n+l*r,i[10]=a*n+d*r,i[11]=c*n+u*r,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[4],l=t[5],d=t[6],u=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+u*n,i[4]=h*r-s*n,i[5]=l*r-o*n,i[6]=d*r-a*n,i[7]=u*r-c*n,i}function ln(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,u=r*o,g=r*a,p=r*c,f=s*o,y=s*a,M=s*c;return i[0]=1-d-p,i[1]=l+M,i[2]=u-y,i[3]=0,i[4]=l-M,i[5]=1-h-p,i[6]=g+f,i[7]=0,i[8]=u+y,i[9]=g-f,i[10]=1-h-d,i[11]=0,i[12]=0,i[13]=0,i[14]=0,i[15]=1,i}function dn(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 Br(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=Br;function zr(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 fn=zr;function mn(i,t,e,n){let r,s,o,a,c,h,l,d,u,g,p=t[0],f=t[1],y=t[2],M=n[0],I=n[1],m=n[2],x=e[0],b=e[1],_=e[2];return Math.abs(p-x)<1e-6&&Math.abs(f-b)<1e-6&&Math.abs(y-_)<1e-6?Fr(i):(d=p-x,u=f-b,g=y-_,r=1/Math.sqrt(d*d+u*u+g*g),d*=r,u*=r,g*=r,s=I*g-m*u,o=m*d-M*g,a=M*u-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=u*a-g*o,h=g*s-d*a,l=d*o-u*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]=u,i[7]=0,i[8]=a,i[9]=l,i[10]=g,i[11]=0,i[12]=-(s*p+o*f+a*y),i[13]=-(c*p+h*f+l*y),i[14]=-(d*p+u*f+g*y),i[15]=1,i)}function jr(){let i=new et(4);return et!=Float32Array&&(i[0]=0,i[1]=0,i[2]=0,i[3]=0),i}function pn(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 Ja=function(){let i=jr();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 ti;(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"})(ti||(ti={}));var Gr=45*Math.PI/180,Ur=1,Qe=.1,Je=500,$r=Object.freeze([1,0,0,0,0,1,0,0,0,0,1,0,0,0,0,1]),q=class extends de{static get IDENTITY(){return Xr()}static get ZERO(){return Vr()}get ELEMENTS(){return 16}get RANK(){return 4}get INDICES(){return ti}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,u,g,p,f,y){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]=u,this[12]=g,this[13]=p,this[14]=f,this[15]=y,this.check()}setRowMajor(t,e,n,r,s,o,a,c,h,l,d,u,g,p,f,y){return this[0]=t,this[1]=s,this[2]=h,this[3]=g,this[4]=e,this[5]=o,this[6]=l,this[7]=p,this[8]=n,this[9]=a,this[10]=d,this[11]=f,this[12]=r,this[13]=c,this[14]=u,this[15]=y,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($r)}fromObject(t){return this.check()}fromQuaternion(t){return ln(this,t),this.check()}frustum(t){let{left:e,right:n,bottom:r,top:s,near:o=Qe,far:a=Je}=t;return a===1/0?qr(this,e,n,r,s,o):dn(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 mn(this,e,n,r),this.check()}ortho(t){let{left:e,right:n,bottom:r,top:s,near:o=Qe,far:a=Je}=t;return fn(this,e,n,r,s,o,a),this.check()}orthographic(t){let{fovy:e=Gr,aspect:n=Ur,focalDistance:r=1,near:s=Qe,far:o=Je}=t;gn(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 gn(e),un(this,e,n,r,s),this.check()}determinant(){return nn(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 tn(this,this),this.check()}invert(){return en(this,this),this.check()}multiplyLeft(t){return Ze(this,t,this),this.check()}multiplyRight(t){return Ze(this,this,t),this.check()}rotateX(t){return an(this,this,t),this.check()}rotateY(t){return cn(this,this,t),this.check()}rotateZ(t){return hn(this,this,t),this.check()}rotateXYZ(t){return this.rotateX(t[0]).rotateY(t[1]).rotateZ(t[2])}rotateAxis(t,e){return on(this,this,t,e),this.check()}scale(t){return sn(this,this,Array.isArray(t)?t:[t,t,t]),this.check()}translate(t){return rn(this,this,t),this.check()}transform(t,e){return t.length===4?(e=pn(e||[-0,-0,-0,-0],t,this),oe(e,4),e):this.transformAsPoint(t,e)}transformAsPoint(t,e){let{length:n}=t,r;switch(n){case 2:r=Vi(e||[-0,-0],t,this);break;case 3:r=he(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return oe(r,t.length),r}transformAsVector(t,e){let n;switch(t.length){case 2:n=Xi(e||[-0,-0],t,this);break;case 3:n=ce(e||[-0,-0,-0],t,this);break;default:throw new Error("Illegal vector")}return oe(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])}},ue,fe;function Vr(){return ue||(ue=new q([0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0]),Object.freeze(ue)),ue}function Xr(){return fe||(fe=new q,Object.freeze(fe)),fe}function gn(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,u=-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]=u,i[15]=0,i}var Hr=.02,Wr=.12,Yr=.15,Kr=.2,ni=[0,1,0],Zr=[255,255,255],Qr=1,ei=.35,ii=255,Jr=1,ts=.01,es={depthCompare:"less-equal",depthWriteEnabled:!1,cullMode:"none"},is=[{name:"instancePosition",format:"float32x3",stepMode:"instance"},{name:"instanceDirection",format:"float32x3",stepMode:"instance"},{name:"instanceScale",format:"float32x3",stepMode:"instance"},{name:"instanceColor",format:"float32x4",stepMode:"instance"}],ns={name:"lightMarker",props:{},uniforms:{},uniformTypes:{viewProjectionMatrix:"mat4x4<f32>"}},rs="inputs.positions * inputs.instanceScale",ss="vec3<f32>(inputs.positions.x * inputs.instanceScale.x, (inputs.positions.y - 0.5) * inputs.instanceScale.y, inputs.positions.z * inputs.instanceScale.z)",os="positions * instanceScale",as="vec3(positions.x * instanceScale.x, (positions.y - 0.5) * instanceScale.y, positions.z * instanceScale.z)",ot=class extends W{lightModelProps;_instanceData;_managedBuffers;buildInstanceData;sizePropNames;constructor(t,e,n){let r=n.buildInstanceData(e),s=xn(t,e.id||n.idPrefix,r),o=new $({lightMarker:ns});o.setProps({lightMarker:{viewProjectionMatrix:bn(e)}});let{source:a,vs:c,fs:h}=us(n.anchorMode),l=e;super(t,{...l,id:e.id||n.idPrefix,source:a,vs:c,fs:h,geometry:n.geometry,shaderInputs:o,bufferLayout:[...is],attributes:s,instanceCount:r.instanceCount,parameters:Mn(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(Mn(this.lightModelProps.parameters)),("viewMatrix"in t||"projectionMatrix"in t)&&(this.shaderInputs.setProps({lightMarker:{viewProjectionMatrix:bn(this.lightModelProps)}}),this.setNeedsRedraw("lightMarker camera")),ds(t,this.sizePropNames)&&this.rebuildInstanceData()}rebuildInstanceData(){let t=this.buildInstanceData(this.lightModelProps),e=xn(this.device,this.id,t);this.setAttributes(e),this.setInstanceCount(t.instanceCount),yn(this._managedBuffers),this._managedBuffers=e,this._instanceData=t}};function _n(i){let t=wn(i.lights),e=ri(i),n=i.pointLightRadius??Hr*e.sceneScale*e.markerScale;return oi(t.length,(r,s)=>({color:si(r),direction:ni,position:r.position,scale:[n,n,n]}),t)}function In(i){let t=An(i.lights),e=ri(i),n=i.spotLightLength??Wr*e.sceneScale*e.markerScale;return oi(t.length,(r,s)=>{let o=jt(r.outerConeAngle??Math.PI/4,0,Math.PI/2-ts),a=Math.tan(o)*n;return{color:si(r),direction:Tn(r.direction),position:r.position,scale:[a,n,a]}},t)}function vn(i){let t=cs(i.lights),e=ri(i),n=i.directionalLightLength??Yr*e.sceneScale*e.markerScale,r=n*Kr;return oi(t.length,(s,o)=>{let a=Tn(s.direction),c=[e.sceneCenter[0]-a[0]*e.sceneScale*ei,e.sceneCenter[1]-a[1]*e.sceneScale*ei,e.sceneCenter[2]-a[2]*e.sceneScale*ei];return{color:si(s),direction:a,position:c,scale:[r,n,r]}},t)}function wn(i){return i.filter(t=>t.type==="point")}function An(i){return i.filter(t=>t.type==="spot")}function cs(i){return i.filter(t=>t.type==="directional")}function ri(i){let t=hs(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]),Jr);return{bounds:t,markerScale:Math.max(i.markerScale??Qr,0),sceneCenter:e,sceneScale:n}}function si(i){let t=i.color||Zr,e=Math.max(i.intensity??1,0),n=jt(.35+.3*Math.log10(e+1),.35,1);return[jt(t[0]/ii,0,1)*n,jt(t[1]/ii,0,1)*n,jt(t[2]/ii,0,1)*n,1]}function Tn(i){let[t,e,n]=i||ni,r=Math.hypot(t,e,n);return r===0?[...ni]:[t/r,e/r,n/r]}function oi(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 hs(i,t){if(t)return ls(t);let e=[...wn(i).map(s=>s.position),...An(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 ls(i){return[[...i[0]],[...i[1]]]}function xn(i,t,e){return{instancePosition:i.createBuffer({id:`${t}-instance-position`,data:me(e.instancePositions,3)}),instanceDirection:i.createBuffer({id:`${t}-instance-direction`,data:me(e.instanceDirections,3)}),instanceScale:i.createBuffer({id:`${t}-instance-scale`,data:me(e.instanceScales,3)}),instanceColor:i.createBuffer({id:`${t}-instance-color`,data:me(e.instanceColors,4)})}}function me(i,t){return i.length>0?i:new Float32Array(t)}function yn(i){for(let t of Object.values(i))t?.destroy()}function bn(i){return new q(i.projectionMatrix).multiplyRight(i.viewMatrix)}function ds(i,t){return"lights"in i||"bounds"in i||"markerScale"in i?!0:t.some(e=>e in i)}function Mn(i){return{...es,...i||{}}}function us(i){let t=i==="apex"?ss:rs,e=i==="apex"?as:os;return{source:`struct lightMarkerUniforms {
|
|
85
|
+
viewProjectionMatrix: mat4x4<f32>,
|
|
86
|
+
};
|
|
87
|
+
|
|
88
|
+
@binding(0) @group(0) var<uniform> lightMarker : lightMarkerUniforms;
|
|
89
|
+
|
|
90
|
+
struct VertexInputs {
|
|
91
|
+
@location(0) positions : vec3<f32>,
|
|
92
|
+
@location(1) instancePosition : vec3<f32>,
|
|
93
|
+
@location(2) instanceDirection : vec3<f32>,
|
|
94
|
+
@location(3) instanceScale : vec3<f32>,
|
|
95
|
+
@location(4) instanceColor : vec4<f32>,
|
|
96
|
+
};
|
|
247
97
|
|
|
248
|
-
|
|
249
|
-
|
|
250
|
-
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
98
|
+
struct FragmentInputs {
|
|
99
|
+
@builtin(position) Position : vec4<f32>,
|
|
100
|
+
@location(0) color : vec4<f32>,
|
|
101
|
+
};
|
|
102
|
+
|
|
103
|
+
fn lightMarker_rotate(localPosition: vec3<f32>, direction: vec3<f32>) -> vec3<f32> {
|
|
104
|
+
let forward = normalize(direction);
|
|
105
|
+
var helperAxis = vec3<f32>(0.0, 1.0, 0.0);
|
|
106
|
+
if (abs(forward.y) > 0.999) {
|
|
107
|
+
helperAxis = vec3<f32>(1.0, 0.0, 0.0);
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
let tangent = normalize(cross(helperAxis, forward));
|
|
111
|
+
let bitangent = cross(forward, tangent);
|
|
112
|
+
return tangent * localPosition.x + forward * localPosition.y + bitangent * localPosition.z;
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
@vertex
|
|
116
|
+
fn vertexMain(inputs: VertexInputs) -> FragmentInputs {
|
|
117
|
+
var outputs : FragmentInputs;
|
|
118
|
+
let localPosition = ${t};
|
|
119
|
+
let worldPosition = inputs.instancePosition + lightMarker_rotate(localPosition, inputs.instanceDirection);
|
|
120
|
+
outputs.Position = lightMarker.viewProjectionMatrix * vec4<f32>(worldPosition, 1.0);
|
|
121
|
+
outputs.color = inputs.instanceColor;
|
|
122
|
+
return outputs;
|
|
123
|
+
}
|
|
254
124
|
|
|
255
125
|
@fragment
|
|
256
|
-
fn fragmentMain(inputs: FragmentInputs) -> @location(0)
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
126
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
|
|
127
|
+
return inputs.color;
|
|
128
|
+
}
|
|
129
|
+
`,vs:`#version 300 es
|
|
260
130
|
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
131
|
+
in vec3 positions;
|
|
132
|
+
in vec3 instancePosition;
|
|
133
|
+
in vec3 instanceDirection;
|
|
134
|
+
in vec3 instanceScale;
|
|
135
|
+
in vec4 instanceColor;
|
|
136
|
+
|
|
137
|
+
uniform lightMarkerUniforms {
|
|
138
|
+
mat4 viewProjectionMatrix;
|
|
139
|
+
} lightMarker;
|
|
140
|
+
|
|
141
|
+
out vec4 vColor;
|
|
142
|
+
|
|
143
|
+
vec3 lightMarker_rotate(vec3 localPosition, vec3 direction) {
|
|
144
|
+
vec3 forward = normalize(direction);
|
|
145
|
+
vec3 helperAxis = abs(forward.y) > 0.999 ? vec3(1.0, 0.0, 0.0) : vec3(0.0, 1.0, 0.0);
|
|
146
|
+
vec3 tangent = normalize(cross(helperAxis, forward));
|
|
147
|
+
vec3 bitangent = cross(forward, tangent);
|
|
148
|
+
return tangent * localPosition.x + forward * localPosition.y + bitangent * localPosition.z;
|
|
264
149
|
}
|
|
265
|
-
`}function Ir(i){return`// Binding 0:1 is reserved for shader passes
|
|
266
|
-
@group(0) @binding(0) var<uniform> brightnessContrast : brightnessContrastUniforms;
|
|
267
|
-
@group(0) @binding(1) var texture: texture_2d<f32>;
|
|
268
|
-
@group(0) @binding(2) var sampler: sampler;
|
|
269
150
|
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
151
|
+
void main(void) {
|
|
152
|
+
vec3 localPosition = ${e};
|
|
153
|
+
vec3 worldPosition = instancePosition + lightMarker_rotate(localPosition, instanceDirection);
|
|
154
|
+
gl_Position = lightMarker.viewProjectionMatrix * vec4(worldPosition, 1.0);
|
|
155
|
+
vColor = instanceColor;
|
|
156
|
+
}
|
|
157
|
+
`,fs:`#version 300 es
|
|
158
|
+
precision highp float;
|
|
159
|
+
|
|
160
|
+
in vec4 vColor;
|
|
161
|
+
out vec4 fragColor;
|
|
162
|
+
|
|
163
|
+
void main(void) {
|
|
164
|
+
fragColor = vColor;
|
|
165
|
+
}
|
|
166
|
+
`}}function jt(i,t,e){return Math.min(e,Math.max(t,i))}var fs=new It({nlat:8,nlong:12,radius:1}),pe=class extends ot{constructor(t,e){super(t,e,{anchorMode:"centered",buildInstanceData:_n,geometry:fs,idPrefix:"point-light-model",sizePropNames:["pointLightRadius"]})}};var ms={x:[2,0,1],y:[0,1,2],z:[1,2,0]},at=class extends V{constructor(t={}){let{id:e=S("truncated-code-geometry")}=t,{indices:n,attributes:r}=ps(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 ps(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),u=Math.sin,g=Math.cos,p=Math.PI,f=g(d),y=u(d),M=a?-2:0,I=s+(c?2:0),m=r+1,x=new Uint16Array(r*(s+h)*6),b=ms[o],_=new Float32Array(l*3),T=new Float32Array(l*3),E=new Float32Array(l*2),L=0,O=0;for(let v=M;v<=I;v++){let P=v/s,C=n*P,A;v<0?(C=0,P=1,A=t):v>s?(C=n,P=1,A=e):A=t+(e-t)*(v/s),(v===-2||v===s+2)&&(A=0,P=0),C-=n/2;for(let B=0;B<m;B++){let tt=u(B*p*2/r),Z=g(B*p*2/r);_[L+b[0]]=tt*A,_[L+b[1]]=C,_[L+b[2]]=Z*A,T[L+b[0]]=v<0||v>s?0:tt*f,T[L+b[1]]=v<0?-1:v>s?1:y,T[L+b[2]]=v<0||v>s?0:Z*f,E[O+0]=B/r,E[O+1]=P,O+=2,L+=3}}for(let v=0;v<s+h;v++)for(let P=0;P<r;P++){let C=(v*r+P)*6;x[C+0]=m*(v+0)+0+P,x[C+1]=m*(v+0)+1+P,x[C+2]=m*(v+1)+1+P,x[C+3]=m*(v+0)+0+P,x[C+4]=m*(v+1)+1+P,x[C+5]=m*(v+1)+0+P}return{indices:x,attributes:{POSITION:_,NORMAL:T,TEXCOORD_0:E}}}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 gs=new ct({cap:!0,nradial:16,nvertical:1,radius:1}),ge=class extends ot{constructor(t,e){super(t,e,{anchorMode:"apex",buildInstanceData:In,geometry:gs,idPrefix:"spot-light-model",sizePropNames:["spotLightLength"]})}};var xs=new ct({cap:!0,nradial:12,nvertical:1,radius:1}),xe=class extends ot{constructor(t,e){super(t,e,{anchorMode:"apex",buildInstanceData:vn,geometry:xs,idPrefix:"directional-light-model",sizePropNames:["directionalLightLength"]})}};function ai(i,t){if(!i)throw new Error(t)}var it=class{id;matrix=new q;display=!0;position=new H;rotation=new H;scale=new H(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 ai(t.length===3,"setPosition requires vector argument"),this.position=t,this}setRotation(t){return ai(t.length===3||t.length===4,"setRotation requires vector argument"),this.rotation=t,this}setScale(t){return ai(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 q().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 q(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 Pn=R(U(),1);var ft=class extends it{children;constructor(t={}){t=Array.isArray(t)?{children:t}:t;let{children:e=[]}=t;Pn.log.assert(e.every(n=>n instanceof it),"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 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 l=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++)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 q}={}){let n=new q(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 q}={}){let n=new q(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 ye=class extends it{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 V{constructor(t={}){let{id:e=S("cube-geometry"),indices:n=!0}=t;super(n?{...t,id:e,topology:"triangle-list",indices:{size:1,value:ys},attributes:{...As,...t.attributes}}:{...t,id:e,topology:"triangle-list",indices:void 0,attributes:{...Ts,...t.attributes}})}},ys=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]),bs=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]),Ms=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]),_s=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]),Is=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]),vs=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]),ws=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]),As={POSITION:{size:3,value:bs},NORMAL:{size:3,value:Ms},TEXCOORD_0:{size:2,value:_s}},Ts={POSITION:{size:3,value:Is},TEXCOORD_0:{size:2,value:vs},COLOR_0:{size:3,value:ws}};var Me=class extends at{constructor(t={}){let{id:e=S("cylinder-geometry"),radius:n=1}=t;super({...t,id:e,bottomRadius:n,topRadius:n})}};var Ps=[-1,0,0,0,1,0,0,0,-1,0,0,1,0,-1,0,1,0,0],Ss=[3,4,5,3,5,1,3,1,0,3,0,4,4,0,2,4,2,5,2,0,1,5,2,1],_e=class extends V{constructor(t={}){let{id:e=S("ico-sphere-geometry")}=t,{indices:n,attributes:r}=Ls(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Ls(i){let{iterations:t=0}=i,e=Math.PI,n=e*2,r=[...Ps],s=[...Ss];r.push(),s.push();let o=(()=>{let l={};return(d,u)=>{d*=3,u*=3;let g=d<u?d:u,p=d>u?d:u,f=`${g}|${p}`;if(f in l)return l[f];let y=r[d],M=r[d+1],I=r[d+2],m=r[u],x=r[u+1],b=r[u+2],_=(y+m)/2,T=(M+x)/2,E=(I+b)/2,L=Math.sqrt(_*_+T*T+E*E);return _/=L,T/=L,E/=L,r.push(_,T,E),l[f]=r.length/3-1}})();for(let l=0;l<t;l++){let d=[];for(let u=0;u<s.length;u+=3){let g=o(s[u+0],s[u+1]),p=o(s[u+1],s[u+2]),f=o(s[u+2],s[u+0]);d.push(f,s[u+0],g,g,s[u+1],p,p,s[u+2],f,g,p,f)}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],u=s[l+1],g=s[l+2],p=d*3,f=u*3,y=g*3,M=d*2,I=u*2,m=g*2,x=r[p+0],b=r[p+1],_=r[p+2],T=Math.acos(_/Math.sqrt(x*x+b*b+_*_)),E=Math.atan2(b,x)+e,L=T/e,O=1-E/n,v=r[f+0],P=r[f+1],C=r[f+2],A=Math.acos(C/Math.sqrt(v*v+P*P+C*C)),B=Math.atan2(P,v)+e,tt=A/e,Z=1-B/n,Xt=r[y+0],qt=r[y+1],Ht=r[y+2],$n=Math.acos(Ht/Math.sqrt(Xt*Xt+qt*qt+Ht*Ht)),Vn=Math.atan2(qt,Xt)+e,mi=$n/e,Wt=1-Vn/n,Xn=[Xt-v,qt-P,Ht-C],qn=[x-v,b-P,_-C],Y=new H(Xn).cross(qn).normalize(),N;(O===0||Z===0||Wt===0)&&(O===0||O>.5)&&(Z===0||Z>.5)&&(Wt===0||Wt>.5)&&(r.push(r[p+0],r[p+1],r[p+2]),N=r.length/3-1,s.push(N),c[N*2+0]=1,c[N*2+1]=L,a[N*3+0]=Y.x,a[N*3+1]=Y.y,a[N*3+2]=Y.z,r.push(r[f+0],r[f+1],r[f+2]),N=r.length/3-1,s.push(N),c[N*2+0]=1,c[N*2+1]=tt,a[N*3+0]=Y.x,a[N*3+1]=Y.y,a[N*3+2]=Y.z,r.push(r[y+0],r[y+1],r[y+2]),N=r.length/3-1,s.push(N),c[N*2+0]=1,c[N*2+1]=mi,a[N*3+0]=Y.x,a[N*3+1]=Y.y,a[N*3+2]=Y.z),a[p+0]=a[f+0]=a[y+0]=Y.x,a[p+1]=a[f+1]=a[y+1]=Y.y,a[p+2]=a[f+2]=a[y+2]=Y.z,c[M+0]=O,c[M+1]=L,c[I+0]=Z,c[I+1]=tt,c[m+0]=Wt,c[m+1]=mi}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 Sn(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 u=t.value[d];for(let g=0;g<h;g++)l[d*h+g]=c[u*h+g]}r[s]={size:h,value:l}}return{attributes:Object.assign({},e,r)}}var Ie=class extends V{constructor(t={}){let{id:e=S("plane-geometry")}=t,{indices:n,attributes:r}=Cs(t);super({...t,id:e,topology:"triangle-list",indices:n,attributes:{...r,...t.attributes}})}};function Cs(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),u=new Float32Array(l*3),g=new Float32Array(l*2);n&&(o=-o);let p=0,f=0;for(let m=0;m<=h;m++)for(let x=0;x<=c;x++){let b=x/c,_=m/h;switch(g[p+0]=n?1-b:b,g[p+1]=_,t){case"x,y":d[f+0]=o*b-o*.5,d[f+1]=a*_-a*.5,d[f+2]=e,u[f+0]=0,u[f+1]=0,u[f+2]=n?1:-1;break;case"x,z":d[f+0]=o*b-o*.5,d[f+1]=e,d[f+2]=a*_-a*.5,u[f+0]=0,u[f+1]=n?1:-1,u[f+2]=0;break;case"y,z":d[f+0]=e,d[f+1]=o*b-o*.5,d[f+2]=a*_-a*.5,u[f+0]=n?1:-1,u[f+1]=0,u[f+2]=0;break;default:throw new Error("PlaneGeometry: unknown type")}p+=2,f+=3}let y=c+1,M=new Uint16Array(c*h*6);for(let m=0;m<h;m++)for(let x=0;x<c;x++){let b=(m*c+x)*6;M[b+0]=(m+0)*y+x,M[b+1]=(m+1)*y+x,M[b+2]=(m+0)*y+x+1,M[b+3]=(m+1)*y+x,M[b+4]=(m+1)*y+x+1,M[b+5]=(m+0)*y+x+1}let I={indices:{size:1,value:M},attributes:{POSITION:{size:3,value:d},NORMAL:{size:3,value:u},TEXCOORD_0:{size:2,value:g}}};return r?Sn(I):I}function Ln(){let i=1,t=1;return()=>(i=Math.sin(t*17.23),t=Math.cos(i*27.92),Es(Math.abs(i*t)*1432.71))}function Es(i){return i-Math.floor(i)}var ci="";function Cn(i){ci=i}async function En(i,t){let e=new Image;return e.crossOrigin=t?.crossOrigin||"anonymous",e.src=i.startsWith("http")?i:ci+i,await e.decode(),t?await createImageBitmap(e,t):await createImageBitmap(e)}async function On(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:ci+i}catch(r){n(r)}})}var Rn=R(rt(),1);var nt=R(U(),1),Tt=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}},Pt=class extends Tt{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:nt.Texture.SAMPLE|nt.Texture.RENDER|nt.Texture.COPY_SRC|nt.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:nt.Texture.SAMPLE|nt.Texture.RENDER|nt.Texture.COPY_SRC|nt.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}},ve=class extends Tt{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"?Os(r):Rs(r);case"sample":let s=`${t.name}_sampleColor`;return n==="wgsl"?ks(s):Ns(s);default:throw new Error(`${t.name} no fragment shader generated for shader pass`)}}function Os(i){return`@group(0) @binding(0) var sourceTexture: texture_2d<f32>;
|
|
167
|
+
@group(0) @binding(2) var sourceTextureSampler: sampler;
|
|
275
168
|
|
|
276
169
|
@fragment
|
|
277
170
|
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
278
|
-
let
|
|
279
|
-
|
|
171
|
+
let texCoord = inputs.coordinate;
|
|
172
|
+
let texSize = vec2f(textureDimensions(sourceTexture));
|
|
173
|
+
|
|
174
|
+
var fragColor = textureSample(sourceTexture, sourceTextureSampler, texCoord);
|
|
280
175
|
fragColor = ${i}(fragColor, texSize, texCoord);
|
|
281
176
|
return fragColor;
|
|
282
177
|
}
|
|
283
|
-
`}function
|
|
178
|
+
`}function ks(i){return`@group(0) @binding(0) var sourceTexture: texture_2d<f32>;
|
|
179
|
+
@group(0) @binding(2) var sourceTextureSampler: sampler;
|
|
180
|
+
|
|
181
|
+
@fragment
|
|
182
|
+
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4f {
|
|
183
|
+
let texCoord = inputs.coordinate;
|
|
184
|
+
let texSize = vec2f(textureDimensions(sourceTexture));
|
|
185
|
+
return ${i}(sourceTexture, sourceTextureSampler, texSize, texCoord);
|
|
186
|
+
}
|
|
187
|
+
`}function Rs(i){return`#version 300 es
|
|
284
188
|
|
|
285
189
|
uniform sampler2D sourceTexture;
|
|
286
190
|
|
|
@@ -298,7 +202,7 @@ void main() {
|
|
|
298
202
|
fragColor = texture(sourceTexture, texCoord);
|
|
299
203
|
fragColor = ${i}(fragColor, texSize, texCoord);
|
|
300
204
|
}
|
|
301
|
-
`}function
|
|
205
|
+
`}function Ns(i){return`#version 300 es
|
|
302
206
|
|
|
303
207
|
uniform sampler2D sourceTexture;
|
|
304
208
|
|
|
@@ -315,24 +219,7 @@ void main() {
|
|
|
315
219
|
|
|
316
220
|
fragColor = ${i}(sourceTexture, texSize, texCoord);
|
|
317
221
|
}
|
|
318
|
-
`}var
|
|
319
|
-
@group(0) @binding(1) var sourceTextureSampler: sampler;
|
|
320
|
-
|
|
321
|
-
@fragment
|
|
322
|
-
fn fragmentMain(inputs: FragmentInputs) -> @location(0) vec4<f32> {
|
|
323
|
-
let texCoord: vec2<f32> = inputs.coordinate;
|
|
324
|
-
return textureSample(sourceTexture, sourceTextureSampler, texCoord);
|
|
325
|
-
}
|
|
326
|
-
`,fs:`#version 300 es
|
|
327
|
-
|
|
328
|
-
uniform sampler2D sourceTexture;
|
|
329
|
-
in vec2 uv;
|
|
330
|
-
out vec4 fragColor;
|
|
331
|
-
|
|
332
|
-
void main() {
|
|
333
|
-
fragColor = texture(sourceTexture, uv);
|
|
334
|
-
}
|
|
335
|
-
`}),this.passRenderers=e.shaderPasses.map(n=>new ze(t,n))}destroy(){for(let t of this.passRenderers)t.destroy();this.swapFramebuffers.destroy(),this.clipSpace.destroy(),this.textureModel.destroy()}resize(t){t||=this.device.getCanvasContext().getDrawingBufferSize(),this.swapFramebuffers.resize({width:t[0],height:t[1]})}renderToScreen(t){let e=this.renderToTexture(t);if(!e)return!1;let s=this.device.getDefaultCanvasContext().getCurrentFramebuffer({depthStencilAttachment:!1}),r=this.device.beginRenderPass({id:"shader-pass-renderer-to-screen",framebuffer:s,clearDepth:1});return this.clipSpace.setBindings({sourceTexture:e}),this.clipSpace.draw(r),r.end(),!0}renderToTexture(t){let{sourceTexture:e}=t;if(!e.isReady)return null;if(this.passRenderers.length===0)return e.texture;this.textureModel.setProps({backgroundTexture:e});let s=this.device.beginRenderPass({id:"shader-pass-renderer-clear-texture",framebuffer:this.swapFramebuffers.current,clearColor:[1,0,0,1]});this.textureModel.draw(s),s.end();let r=!0;for(let o of this.passRenderers)for(let a of o.subPassRenderers){r||this.swapFramebuffers.swap(),r=!1;let h={sourceTexture:this.swapFramebuffers.current.colorAttachments[0].texture},l=this.device.beginRenderPass({id:"shader-pass-renderer-run-pass",framebuffer:this.swapFramebuffers.next,clearColor:[0,0,0,1],clearDepth:1});a.render({renderPass:l,bindings:h}),l.end()}return this.swapFramebuffers.swap(),this.swapFramebuffers.current.colorAttachments[0].texture}},ze=class{shaderPass;subPassRenderers;constructor(t,e,s={}){this.shaderPass=e;let r=e.passes||[];this.subPassRenderers=r.map(n=>new $e(t,e,n))}destroy(){for(let t of this.subPassRenderers)t.destroy()}},$e=class{model;shaderPass;subPass;constructor(t,e,s){this.shaderPass=e,this.subPass=s;let r=s.action||s.filter&&"filter"||s.sampler&&"sample"||"filter",n=es({shaderPass:e,action:r,shadingLanguage:t.info.shadingLanguage});this.model=new it(t,{id:`${e.name}-subpass`,source:n,fs:n,modules:[e],parameters:{depthWriteEnabled:!1}})}destroy(){this.model.destroy()}render(t){let{renderPass:e,bindings:s}=t;this.model.shaderInputs.setProps({[this.shaderPass.name]:this.shaderPass.uniforms||{}}),this.model.shaderInputs.setProps({[this.shaderPass.name]:this.subPass.uniforms||{}}),this.model.setBindings(s||{}),this.model.draw(e)}};var Lr=[0,1,1,1],Q=-1,Rr={isActive:"i32",indexMode:"i32",batchIndex:"i32",isHighlightActive:"i32",highlightedBatchIndex:"i32",highlightedObjectIndex:"i32",highlightColor:"vec4<f32>"},Tt=`precision highp float;
|
|
222
|
+
`}var we=class{device;shaderInputs;passRenderers;swapFramebuffers;textureModel;constructor(t,e){this.device=t,e.shaderPasses.map(s=>(0,Rn.initializeShaderModule)(s));let n=e.shaderPasses.reduce((s,o)=>({...s,[o.name]:o}),{});this.shaderInputs=e.shaderInputs||new $(n);let r=t.getCanvasContext().getDrawingBufferSize();this.swapFramebuffers=new Pt(t,{colorAttachments:[t.preferredColorFormat],width:r[0],height:r[1]}),this.textureModel=new _t(t,{backgroundTexture:this.swapFramebuffers.current.colorAttachments[0].texture}),this.passRenderers=e.shaderPasses.map(s=>new hi(t,s))}destroy(){for(let t of this.passRenderers)t.destroy();this.swapFramebuffers.destroy(),this.textureModel.destroy()}resize(t){t||=this.device.getCanvasContext().getDrawingBufferSize(),this.swapFramebuffers.resize({width:t[0],height:t[1]})}renderToScreen(t){let e=this.renderToTexture(t);if(!e)return!1;let n=this.device.getDefaultCanvasContext().getCurrentFramebuffer({depthStencilFormat:!1}),r=this.device.beginRenderPass({id:"shader-pass-renderer-to-screen",framebuffer:n,clearDepth:!1});return this.textureModel.setProps({backgroundTexture:e}),this.textureModel.draw(r),r.end(),!0}renderToTexture(t){let{sourceTexture:e}=t;if(!e.isReady)return null;if(this.passRenderers.length===0)return e.texture;this.textureModel.setProps({backgroundTexture:e});let n=this.device.beginRenderPass({id:"shader-pass-renderer-clear-texture",framebuffer:this.swapFramebuffers.current,clearColor:[1,0,0,1]});this.textureModel.draw(n),n.end();let r=!0;for(let o of this.passRenderers)for(let a of o.subPassRenderers){r||this.swapFramebuffers.swap(),r=!1;let h={sourceTexture:this.swapFramebuffers.current.colorAttachments[0].texture},l=this.device.beginRenderPass({id:"shader-pass-renderer-run-pass",framebuffer:this.swapFramebuffers.next,clearColor:[0,0,0,1],clearDepth:1});a.render({renderPass:l,bindings:h}),l.end()}return this.swapFramebuffers.swap(),this.swapFramebuffers.current.colorAttachments[0].texture}},hi=class{shaderPass;subPassRenderers;constructor(t,e,n={}){this.shaderPass=e;let r=e.passes||[];this.subPassRenderers=r.map(s=>new li(t,e,s))}destroy(){for(let t of this.subPassRenderers)t.destroy()}},li=class{model;shaderPass;subPass;constructor(t,e,n){this.shaderPass=e,this.subPass=n;let r=n.action||n.filter&&"filter"||n.sampler&&"sample"||"filter",s=kn({shaderPass:e,action:r,shadingLanguage:t.info.shadingLanguage});this.model=new st(t,{id:`${e.name}-subpass`,source:s,fs:s,modules:[e],parameters:{depthWriteEnabled:!1}})}destroy(){this.model.destroy()}render(t){let{renderPass:e,bindings:n}=t;this.model.shaderInputs.setProps({[this.shaderPass.name]:this.shaderPass.uniforms||{}}),this.model.shaderInputs.setProps({[this.shaderPass.name]:this.subPass.uniforms||{}}),this.model.setBindings(n||{}),this.model.draw(e)}};var D=R(U(),1),Nn=R(rt(),1);var di=2,Ds=1e4,ui=class{device;id;pipelineFactory;shaderFactory;userData={};bindings={};pipeline;source;shader;shaderInputs;_uniformStore;_pipelineNeedsUpdate="newly created";_getModuleUniforms;props;_destroyed=!1;constructor(t,e){if(t.type!=="webgpu")throw new Error("Computation is only supported in WebGPU");this.props={...ui.defaultProps,...e},e=this.props,this.id=e.id||S("model"),this.device=t,Object.assign(this.userData,e.userData);let n=Object.fromEntries(this.props.modules?.map(h=>[h.name,h])||[]);this.shaderInputs=e.shaderInputs||new $(n),this.setShaderInputs(this.shaderInputs);let r=Fs(t),s=(this.props.modules?.length>0?this.props.modules:this.shaderInputs?.getModules())||[];this.props.shaderLayout=xt(this.props.shaderLayout,s)||null,this.pipelineFactory=e.pipelineFactory||D.PipelineFactory.getDefaultPipelineFactory(this.device),this.shaderFactory=e.shaderFactory||D.ShaderFactory.getDefaultShaderFactory(this.device);let{source:o,getUniforms:a}=this.props.shaderAssembler.assembleWGSLShader({platformInfo:r,...this.props,modules:s});this.source=o,this._getModuleUniforms=a;let c=t.getShaderLayout?.(this.source);this.props.shaderLayout=xt(this.props.shaderLayout||c||null,s)||null,this.pipeline=this._updatePipeline(),e.bindings&&this.setBindings(e.bindings),Object.seal(this)}destroy(){this._destroyed||(this.pipelineFactory.release(this.pipeline),this.shaderFactory.release(this.shader),this._uniformStore.destroy(),this._destroyed=!0)}predraw(){this.updateShaderInputs()}dispatch(t,e,n,r){try{this._logDrawCallStart(),this.pipeline=this._updatePipeline(),this.pipeline.setBindings(this.bindings),t.setPipeline(this.pipeline),t.setBindings({}),t.dispatch(e,n,r)}finally{this._logDrawCallEnd()}}setVertexCount(t){}setInstanceCount(t){}setShaderInputs(t){this.shaderInputs=t,this._uniformStore=new D.UniformStore(this.shaderInputs.modules);for(let[e,n]of Object.entries(this.shaderInputs.modules))if(yt(n)){let r=this._uniformStore.getManagedUniformBuffer(this.device,e);this.bindings[`${e}Uniforms`]=r}}setShaderModuleProps(t){let e=this._getModuleUniforms(t),n=Object.keys(e).filter(s=>{let o=e[s];return!kt(o)&&typeof o!="number"&&typeof o!="boolean"}),r={};for(let s of n)r[s]=e[s],delete e[s]}updateShaderInputs(){this._uniformStore.setUniforms(this.shaderInputs.getUniformValues())}setBindings(t){Object.assign(this.bindings,t)}_setPipelineNeedsUpdate(t){this._pipelineNeedsUpdate=this._pipelineNeedsUpdate||t}_updatePipeline(){if(this._pipelineNeedsUpdate){let t=null;this.pipeline&&(D.log.log(1,`Model ${this.id}: Recreating pipeline because "${this._pipelineNeedsUpdate}".`)(),t=this.shader),this._pipelineNeedsUpdate=!1,this.shader=this.shaderFactory.createShader({id:`${this.id}-fragment`,stage:"compute",source:this.source,debugShaders:this.props.debugShaders}),this.pipeline=this.pipelineFactory.createComputePipeline({...this.props,shader:this.shader}),t&&this.shaderFactory.release(t)}return this.pipeline}_lastLogTime=0;_logOpen=!1;_logDrawCallStart(){let t=D.log.level>3?0:Ds;D.log.level<2||Date.now()-this._lastLogTime<t||(this._lastLogTime=Date.now(),this._logOpen=!0,D.log.group(di,`>>> DRAWING MODEL ${this.id}`,{collapsed:D.log.level<=2})())}_logDrawCallEnd(){if(this._logOpen){let t=this.shaderInputs.getDebugTable();D.log.table(di,t)(),D.log.groupEnd(di)(),this._logOpen=!1}}_drawCount=0;_getBufferOrConstantValues(t,e){let n=D.dataTypeDecoder.getTypedArrayConstructor(e);return(t instanceof D.Buffer?new n(t.debugData):t).toString()}},Gt=ui;K(Gt,"defaultProps",{...D.ComputePipeline.defaultProps,id:"unnamed",handle:void 0,userData:{},source:"",modules:[],defines:{},bindings:void 0,shaderInputs:void 0,pipelineFactory:void 0,shaderFactory:void 0,shaderAssembler:Nn.ShaderAssembler.getDefaultShaderAssembler(),debugShaders:void 0});function Fs(i){return{type:i.type,shaderLanguage:i.info.shadingLanguage,shaderLanguageVersion:i.info.shadingLanguageVersion,gpu:i.info.gpu,features:i.features}}var Q=R(U(),1);var Bs=[0,1,1,1],G=-1,zs={isActive:"i32",indexMode:"i32",batchIndex:"i32",isHighlightActive:"i32",highlightedBatchIndex:"i32",highlightedObjectIndex:"i32",highlightColor:"vec4<f32>"},St=`precision highp float;
|
|
336
223
|
precision highp int;
|
|
337
224
|
|
|
338
225
|
uniform pickingUniforms {
|
|
@@ -345,56 +232,98 @@ uniform pickingUniforms {
|
|
|
345
232
|
int highlightedObjectIndex;
|
|
346
233
|
vec4 highlightColor;
|
|
347
234
|
} picking;
|
|
348
|
-
`,
|
|
349
|
-
isActive:
|
|
350
|
-
indexMode:
|
|
351
|
-
batchIndex:
|
|
352
|
-
|
|
353
|
-
isHighlightActive:
|
|
354
|
-
highlightedBatchIndex:
|
|
355
|
-
highlightedObjectIndex:
|
|
356
|
-
highlightColor: vec4<f32
|
|
357
|
-
}
|
|
358
|
-
`;function Or(i={},t){let e={...t};switch(i.isActive!==void 0&&(e.isActive=Boolean(i.isActive)),i.indexMode){case"instance":e.indexMode=0;break;case"custom":e.indexMode=1;break;case void 0:break}switch(i.highlightedObjectIndex){case void 0:break;case null:e.isHighlightActive=!1,e.highlightedObjectIndex=Q;break;default:e.isHighlightActive=!0,e.highlightedObjectIndex=i.highlightedObjectIndex}return typeof i.highlightedBatchIndex=="number"&&(e.highlightedBatchIndex=i.highlightedBatchIndex),i.highlightColor&&(e.highlightColor=i.highlightColor),e}var xe={props:{},uniforms:{},name:"picking",uniformTypes:Rr,defaultUniforms:{isActive:!1,indexMode:0,batchIndex:0,isHighlightActive:!0,highlightedBatchIndex:Q,highlightedObjectIndex:Q,highlightColor:Lr},getUniforms:Or};var Be=class{device;props;pickInfo={batchIndex:null,objectIndex:null};framebuffer=null;constructor(t,e){this.device=t,this.props={...Be.defaultProps,...e}}destroy(){this.framebuffer?.destroy()}getFramebuffer(){return this.framebuffer||(this.framebuffer=this.device.createFramebuffer({colorAttachments:["rgba8unorm","rg32sint"],depthStencilAttachment:"depth24plus"})),this.framebuffer}clearPickState(){this.props.shaderInputs.setProps({picking:{highlightedObjectIndex:null}})}beginRenderPass(){let t=this.getFramebuffer();return t.resize(this.device.getDefaultCanvasContext().getDevicePixelSize()),this.props.shaderInputs?.setProps({picking:{isActive:!0}}),this.device.beginRenderPass({framebuffer:t,clearColors:[new Float32Array([0,0,0,0]),new Int32Array([-1,-1,0,0])],clearDepth:1})}async updatePickInfo(t){let e=this.getFramebuffer(),[s,r]=this.getPickPosition(t),n=this.device.readPixelsToArrayWebGL(e,{sourceX:s,sourceY:r,sourceWidth:1,sourceHeight:1,sourceAttachment:1});if(!n)return null;let o={objectIndex:n[0]===Q?null:n[0],batchIndex:n[1]===Q?null:n[1]};return(o.objectIndex!==this.pickInfo.objectIndex||o.batchIndex!==this.pickInfo.batchIndex)&&(this.pickInfo=o,this.props.onObjectPicked(o)),this.props.shaderInputs?.setProps({picking:{isActive:!1,highlightedBatchIndex:o.batchIndex,highlightedObjectIndex:o.objectIndex}}),this.pickInfo}getPickPosition(t){let e=this.device.getDefaultCanvasContext().cssToDevicePixels(t),s=e.x+Math.floor(e.width/2),r=e.y+Math.floor(e.height/2);return[s,r]}},Dt=Be;B(Dt,"defaultProps",{shaderInputs:void 0,onObjectPicked:()=>{}});var kr=`${ge}
|
|
235
|
+
`,Ae=`struct pickingUniforms {
|
|
236
|
+
isActive: i32,
|
|
237
|
+
indexMode: i32,
|
|
238
|
+
batchIndex: i32,
|
|
239
|
+
|
|
240
|
+
isHighlightActive: i32,
|
|
241
|
+
highlightedBatchIndex: i32,
|
|
242
|
+
highlightedObjectIndex: i32,
|
|
243
|
+
highlightColor: vec4<f32>,
|
|
244
|
+
};
|
|
359
245
|
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
const INDEX_PICKING_INVALID_INDEX = ${Q}; // 2^32 - 1
|
|
246
|
+
@group(0) @binding(auto) var<uniform> picking: pickingUniforms;
|
|
247
|
+
`;function js(i={},t){let e={...t};switch(i.isActive!==void 0&&(e.isActive=Boolean(i.isActive)),i.indexMode){case"instance":e.indexMode=0;break;case"attribute":e.indexMode=1;break;case void 0:break}switch(typeof i.batchIndex=="number"&&(e.batchIndex=i.batchIndex),i.highlightedObjectIndex){case void 0:break;case null:e.isHighlightActive=!1,e.highlightedObjectIndex=G;break;default:e.isHighlightActive=!0,e.highlightedObjectIndex=i.highlightedObjectIndex}switch(i.highlightedBatchIndex){case void 0:break;case null:e.isHighlightActive=!1,e.highlightedBatchIndex=G;break;default:e.isHighlightActive=!0,e.highlightedBatchIndex=i.highlightedBatchIndex}return i.highlightColor&&(e.highlightColor=i.highlightColor),e}var Lt={props:{},uniforms:{},name:"picking",uniformTypes:zs,defaultUniforms:{isActive:!1,indexMode:0,batchIndex:0,isHighlightActive:!1,highlightedBatchIndex:G,highlightedObjectIndex:G,highlightColor:Bs},getUniforms:js};var Dn=1,Gs=new Int32Array([G,G,0,0]);function Pe(i,t="color",e=i==="webgpu"){if(t==="auto")return e?"index":"color";if(t==="index"&&!e)throw new Error(`Picking mode "${t}" requires WebGPU or a WebGL device that supports renderable rg32sint textures.`);return t}function fi(i){return i.type==="webgpu"||i.type==="webgl"&&i.isTextureFormatRenderable("rg32sint")}var zn=Pe;function Fn(i){return{objectIndex:i[0]===G?null:i[0],batchIndex:i[1]===G?null:i[1]}}function Bn(i){let t=i[0]+i[1]*256+i[2]*65536;if(t===0)return{objectIndex:null,batchIndex:null};let e=i[3]>0?i[3]-1:0;return{objectIndex:t-1,batchIndex:e}}var Te=class{device;props;mode;pickInfo={batchIndex:null,objectIndex:null};framebuffer=null;constructor(t,e){this.device=t,this.props={...Te.defaultProps,...e};let n=e.mode??e.backend??Te.defaultProps.mode;this.props.mode=n,this.props.backend=n,this.mode=Pe(this.device.type,n,fi(this.device))}destroy(){this.framebuffer?.destroy()}getFramebuffer(){return this.framebuffer||(this.framebuffer=this.mode==="index"?this.createIndexFramebuffer():this.createColorFramebuffer()),this.framebuffer}clearPickState(){this.setPickingProps({highlightedBatchIndex:null,highlightedObjectIndex:null})}beginRenderPass(){let t=this.getFramebuffer();return t.resize(this.device.getDefaultCanvasContext().getDevicePixelSize()),this.setPickingProps({isActive:!0}),this.mode==="index"?this.device.beginRenderPass({framebuffer:t,clearColors:[new Float32Array([0,0,0,0]),Gs],clearDepth:1}):this.device.beginRenderPass({framebuffer:t,clearColor:[0,0,0,0],clearDepth:1})}async updatePickInfo(t){let e=this.getFramebuffer(),n=this.getPickPosition(t),r=await this.readPickInfo(e,n);return r?(this.hasPickInfoChanged(r)&&(this.pickInfo=r,this.props.onObjectPicked(r)),this.setPickingProps({isActive:!1,highlightedBatchIndex:r.batchIndex,highlightedObjectIndex:r.objectIndex}),this.pickInfo):null}getPickPosition(t){let e=this.device.type!=="webgpu",n=this.device.getDefaultCanvasContext().cssToDevicePixels(t,e),r=n.x+Math.floor(n.width/2),s=n.y+Math.floor(n.height/2);return[r,s]}createIndexFramebuffer(){let t=this.device.createTexture({format:"rgba8unorm",width:1,height:1,usage:Q.Texture.RENDER_ATTACHMENT}),e=this.device.createTexture({format:"rg32sint",width:1,height:1,usage:Q.Texture.RENDER_ATTACHMENT|Q.Texture.COPY_SRC});return this.device.createFramebuffer({colorAttachments:[t,e],depthStencilAttachment:"depth24plus"})}createColorFramebuffer(){let t=this.device.createTexture({format:"rgba8unorm",width:1,height:1,usage:Q.Texture.RENDER_ATTACHMENT|Q.Texture.COPY_SRC});return this.device.createFramebuffer({colorAttachments:[t],depthStencilAttachment:"depth24plus"})}setPickingProps(t){this.props.shaderInputs?.setProps({picking:t})}async readPickInfo(t,e){return this.mode==="index"?this.readIndexPickInfo(t,e):this.readColorPickInfo(t,e)}async readIndexPickInfo(t,[e,n]){if(this.device.type==="webgpu"){let s=t.colorAttachments[Dn]?.texture;if(!s)return null;let o=s.computeMemoryLayout({width:1,height:1}),a=this.device.createBuffer({byteLength:o.byteLength,usage:Q.Buffer.COPY_DST|Q.Buffer.MAP_READ});try{s.readBuffer({x:e,y:n,width:1,height:1},a);let c=await a.readAsync(0,o.byteLength);return Fn(new Int32Array(c.buffer,c.byteOffset,2))}finally{a.destroy()}}let r=this.device.readPixelsToArrayWebGL(t,{sourceX:e,sourceY:n,sourceWidth:1,sourceHeight:1,sourceAttachment:Dn});return r?Fn(new Int32Array(r.buffer,r.byteOffset,2)):null}async readColorPickInfo(t,[e,n]){if(this.device.type==="webgpu"){let s=t.colorAttachments[0]?.texture;if(!s)return null;let o=s.computeMemoryLayout({width:1,height:1}),a=this.device.createBuffer({byteLength:o.byteLength,usage:Q.Buffer.COPY_DST|Q.Buffer.MAP_READ});try{s.readBuffer({x:e,y:n,width:1,height:1},a);let c=await a.readAsync(0,o.byteLength);return Bn(new Uint8Array(c.buffer,c.byteOffset,4))}finally{a.destroy()}}let r=this.device.readPixelsToArrayWebGL(t,{sourceX:e,sourceY:n,sourceWidth:1,sourceHeight:1,sourceAttachment:0});return r?Bn(new Uint8Array(r.buffer,r.byteOffset,4)):null}hasPickInfoChanged(t){return t.objectIndex!==this.pickInfo.objectIndex||t.batchIndex!==this.pickInfo.batchIndex}},Ut=Te;K(Ut,"defaultProps",{shaderInputs:void 0,onObjectPicked:()=>{},mode:"color",backend:"color"});var Us=`${Ae}
|
|
363
248
|
|
|
364
|
-
|
|
365
|
-
|
|
366
|
-
|
|
249
|
+
const COLOR_PICKING_INVALID_INDEX = ${G};
|
|
250
|
+
const COLOR_PICKING_MAX_OBJECT_INDEX = 16777214;
|
|
251
|
+
const COLOR_PICKING_MAX_BATCH_INDEX = 254;
|
|
367
252
|
|
|
368
|
-
|
|
253
|
+
fn picking_setObjectIndex(objectIndex: i32) -> i32 {
|
|
254
|
+
return objectIndex;
|
|
255
|
+
}
|
|
369
256
|
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
|
|
373
|
-
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
|
|
381
|
-
|
|
257
|
+
fn picking_isObjectHighlighted(objectIndex: i32) -> bool {
|
|
258
|
+
return
|
|
259
|
+
picking.isHighlightActive != 0 &&
|
|
260
|
+
picking.highlightedBatchIndex == picking.batchIndex &&
|
|
261
|
+
picking.highlightedObjectIndex == objectIndex;
|
|
262
|
+
}
|
|
263
|
+
|
|
264
|
+
fn picking_filterHighlightColor(color: vec4<f32>, objectIndex: i32) -> vec4<f32> {
|
|
265
|
+
if (picking.isActive != 0 || !picking_isObjectHighlighted(objectIndex)) {
|
|
266
|
+
return color;
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
let highLightAlpha = picking.highlightColor.a;
|
|
270
|
+
let blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
271
|
+
if (blendedAlpha == 0.0) {
|
|
272
|
+
return vec4<f32>(color.rgb, 0.0);
|
|
382
273
|
}
|
|
274
|
+
|
|
275
|
+
let highLightRatio = highLightAlpha / blendedAlpha;
|
|
276
|
+
let blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
277
|
+
return vec4<f32>(blendedRGB, blendedAlpha);
|
|
278
|
+
}
|
|
279
|
+
|
|
280
|
+
fn picking_canEncodePickInfo(objectIndex: i32) -> bool {
|
|
281
|
+
return
|
|
282
|
+
objectIndex != COLOR_PICKING_INVALID_INDEX &&
|
|
283
|
+
objectIndex >= 0 &&
|
|
284
|
+
objectIndex <= COLOR_PICKING_MAX_OBJECT_INDEX &&
|
|
285
|
+
picking.batchIndex >= 0 &&
|
|
286
|
+
picking.batchIndex <= COLOR_PICKING_MAX_BATCH_INDEX;
|
|
287
|
+
}
|
|
288
|
+
|
|
289
|
+
fn picking_getPickingColor(objectIndex: i32) -> vec4<f32> {
|
|
290
|
+
if (!picking_canEncodePickInfo(objectIndex)) {
|
|
291
|
+
return vec4<f32>(0.0, 0.0, 0.0, 0.0);
|
|
292
|
+
}
|
|
293
|
+
|
|
294
|
+
let encodedObjectIndex = objectIndex + 1;
|
|
295
|
+
let red = encodedObjectIndex % 256;
|
|
296
|
+
let green = (encodedObjectIndex / 256) % 256;
|
|
297
|
+
let blue = (encodedObjectIndex / 65536) % 256;
|
|
298
|
+
let alpha = picking.batchIndex + 1;
|
|
299
|
+
|
|
300
|
+
return vec4<f32>(
|
|
301
|
+
f32(red) / 255.0,
|
|
302
|
+
f32(green) / 255.0,
|
|
303
|
+
f32(blue) / 255.0,
|
|
304
|
+
f32(alpha) / 255.0
|
|
305
|
+
);
|
|
383
306
|
}
|
|
384
307
|
|
|
385
|
-
|
|
308
|
+
fn picking_filterPickingColor(color: vec4<f32>, objectIndex: i32) -> vec4<f32> {
|
|
309
|
+
if (picking.isActive != 0) {
|
|
310
|
+
if (!picking_canEncodePickInfo(objectIndex)) {
|
|
311
|
+
discard;
|
|
312
|
+
}
|
|
313
|
+
return picking_getPickingColor(objectIndex);
|
|
314
|
+
}
|
|
315
|
+
|
|
316
|
+
return color;
|
|
317
|
+
}
|
|
318
|
+
`,$s=`${St}
|
|
386
319
|
|
|
387
320
|
const int INDEX_PICKING_MODE_INSTANCE = 0;
|
|
388
321
|
const int INDEX_PICKING_MODE_CUSTOM = 1;
|
|
389
322
|
|
|
390
|
-
const int
|
|
323
|
+
const int COLOR_PICKING_INVALID_INDEX = ${G};
|
|
391
324
|
|
|
392
325
|
flat out int picking_objectIndex;
|
|
393
326
|
|
|
394
|
-
/**
|
|
395
|
-
* Vertex shaders should call this function to set the object index.
|
|
396
|
-
* If using instance or vertex mode, argument will be ignored, 0 can be supplied.
|
|
397
|
-
*/
|
|
398
327
|
void picking_setObjectIndex(int objectIndex) {
|
|
399
328
|
switch (picking.indexMode) {
|
|
400
329
|
case INDEX_PICKING_MODE_INSTANCE:
|
|
@@ -405,38 +334,31 @@ void picking_setObjectIndex(int objectIndex) {
|
|
|
405
334
|
break;
|
|
406
335
|
}
|
|
407
336
|
}
|
|
408
|
-
`,
|
|
337
|
+
`,Vs=`${St}
|
|
409
338
|
|
|
410
|
-
const int
|
|
339
|
+
const int COLOR_PICKING_INVALID_INDEX = ${G};
|
|
340
|
+
const int COLOR_PICKING_MAX_OBJECT_INDEX = 16777214;
|
|
341
|
+
const int COLOR_PICKING_MAX_BATCH_INDEX = 254;
|
|
411
342
|
|
|
412
343
|
flat in int picking_objectIndex;
|
|
413
344
|
|
|
414
|
-
/**
|
|
415
|
-
* Check if this vertex is highlighted (part of the selected batch and object)
|
|
416
|
-
*/
|
|
417
345
|
bool picking_isFragmentHighlighted() {
|
|
418
|
-
return
|
|
346
|
+
return
|
|
419
347
|
bool(picking.isHighlightActive) &&
|
|
420
348
|
picking.highlightedBatchIndex == picking.batchIndex &&
|
|
421
349
|
picking.highlightedObjectIndex == picking_objectIndex
|
|
422
350
|
;
|
|
423
351
|
}
|
|
424
352
|
|
|
425
|
-
/**
|
|
426
|
-
* Returns highlight color if this item is selected.
|
|
427
|
-
*/
|
|
428
353
|
vec4 picking_filterHighlightColor(vec4 color) {
|
|
429
|
-
// If we are still picking, we don't highlight
|
|
430
354
|
if (bool(picking.isActive)) {
|
|
431
355
|
return color;
|
|
432
356
|
}
|
|
433
357
|
|
|
434
|
-
// If we are not highlighted, return color as is
|
|
435
358
|
if (!picking_isFragmentHighlighted()) {
|
|
436
359
|
return color;
|
|
437
360
|
}
|
|
438
|
-
|
|
439
|
-
// Blend in highlight color based on its alpha value
|
|
361
|
+
|
|
440
362
|
float highLightAlpha = picking.highlightColor.a;
|
|
441
363
|
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
442
364
|
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
@@ -445,147 +367,170 @@ vec4 picking_filterHighlightColor(vec4 color) {
|
|
|
445
367
|
return vec4(blendedRGB, blendedAlpha);
|
|
446
368
|
}
|
|
447
369
|
|
|
448
|
-
|
|
449
|
-
|
|
450
|
-
|
|
451
|
-
|
|
452
|
-
|
|
453
|
-
|
|
454
|
-
|
|
370
|
+
bool picking_canEncodePickInfo(int objectIndex) {
|
|
371
|
+
return
|
|
372
|
+
objectIndex != COLOR_PICKING_INVALID_INDEX &&
|
|
373
|
+
objectIndex >= 0 &&
|
|
374
|
+
objectIndex <= COLOR_PICKING_MAX_OBJECT_INDEX &&
|
|
375
|
+
picking.batchIndex >= 0 &&
|
|
376
|
+
picking.batchIndex <= COLOR_PICKING_MAX_BATCH_INDEX;
|
|
377
|
+
}
|
|
378
|
+
|
|
379
|
+
vec4 picking_getPickingColor() {
|
|
380
|
+
if (!picking_canEncodePickInfo(picking_objectIndex)) {
|
|
381
|
+
return vec4(0.0);
|
|
382
|
+
}
|
|
383
|
+
|
|
384
|
+
int encodedObjectIndex = picking_objectIndex + 1;
|
|
385
|
+
int red = encodedObjectIndex % 256;
|
|
386
|
+
int green = (encodedObjectIndex / 256) % 256;
|
|
387
|
+
int blue = (encodedObjectIndex / 65536) % 256;
|
|
388
|
+
int alpha = picking.batchIndex + 1;
|
|
389
|
+
|
|
390
|
+
return vec4(float(red), float(green), float(blue), float(alpha)) / 255.0;
|
|
455
391
|
}
|
|
456
392
|
|
|
457
393
|
vec4 picking_filterPickingColor(vec4 color) {
|
|
458
394
|
if (bool(picking.isActive)) {
|
|
459
|
-
if (picking_objectIndex
|
|
395
|
+
if (!picking_canEncodePickInfo(picking_objectIndex)) {
|
|
460
396
|
discard;
|
|
461
397
|
}
|
|
398
|
+
return picking_getPickingColor();
|
|
462
399
|
}
|
|
400
|
+
|
|
463
401
|
return color;
|
|
464
402
|
}
|
|
465
403
|
|
|
466
|
-
/*
|
|
467
|
-
* Returns picking color if picking is enabled if not
|
|
468
|
-
* highlight color if this item is selected, otherwise unmodified argument.
|
|
469
|
-
*/
|
|
470
404
|
vec4 picking_filterColor(vec4 color) {
|
|
471
405
|
vec4 outColor = color;
|
|
472
406
|
outColor = picking_filterHighlightColor(outColor);
|
|
473
407
|
outColor = picking_filterPickingColor(outColor);
|
|
474
408
|
return outColor;
|
|
475
409
|
}
|
|
476
|
-
|
|
477
|
-
`,zr=`${Tt}
|
|
478
|
-
out vec4 picking_vRGBcolor_Avalid;
|
|
410
|
+
`,$t={...Lt,name:"picking",source:Us,vs:$s,fs:Vs};var Xs=`${Ae}
|
|
479
411
|
|
|
480
|
-
|
|
481
|
-
|
|
482
|
-
|
|
483
|
-
}
|
|
484
|
-
|
|
485
|
-
// Normalize unsigned byte color to 0-1 range
|
|
486
|
-
vec4 picking_normalizeColor(vec4 color) {
|
|
487
|
-
return picking.useFloatColors > 0.5 ? color : color / 255.0;
|
|
488
|
-
}
|
|
489
|
-
|
|
490
|
-
bool picking_isColorZero(vec3 color) {
|
|
491
|
-
return dot(color, vec3(1.0)) < 0.00001;
|
|
492
|
-
}
|
|
412
|
+
const INDEX_PICKING_MODE_INSTANCE = 0;
|
|
413
|
+
const INDEX_PICKING_MODE_CUSTOM = 1;
|
|
414
|
+
const INDEX_PICKING_INVALID_INDEX = ${G}; // 2^32 - 1
|
|
493
415
|
|
|
494
|
-
|
|
495
|
-
|
|
416
|
+
/**
|
|
417
|
+
* WGSL shaders need to carry the returned object index through their own stage outputs.
|
|
418
|
+
*/
|
|
419
|
+
fn picking_setObjectIndex(objectIndex: i32) -> i32 {
|
|
420
|
+
return objectIndex;
|
|
496
421
|
}
|
|
497
422
|
|
|
498
|
-
|
|
499
|
-
bool isVertexHighlighted(vec3 vertexColor) {
|
|
500
|
-
vec3 highlightedObjectColor = picking_normalizeColor(picking.highlightedObjectColor);
|
|
423
|
+
fn picking_isObjectHighlighted(objectIndex: i32) -> bool {
|
|
501
424
|
return
|
|
502
|
-
|
|
425
|
+
picking.isHighlightActive != 0 &&
|
|
426
|
+
picking.highlightedBatchIndex == picking.batchIndex &&
|
|
427
|
+
picking.highlightedObjectIndex == objectIndex;
|
|
503
428
|
}
|
|
504
429
|
|
|
505
|
-
|
|
506
|
-
|
|
507
|
-
|
|
508
|
-
|
|
509
|
-
if (bool(picking.isActive)) {
|
|
510
|
-
// Use alpha as the validity flag. If pickingColor is [0, 0, 0] fragment is non-pickable
|
|
511
|
-
picking_vRGBcolor_Avalid.a = float(picking_isColorValid(pickingColor));
|
|
512
|
-
|
|
513
|
-
if (!bool(picking.isAttribute)) {
|
|
514
|
-
// Stores the picking color so that the fragment shader can render it during picking
|
|
515
|
-
picking_vRGBcolor_Avalid.rgb = pickingColor;
|
|
516
|
-
}
|
|
517
|
-
} else {
|
|
518
|
-
// Do the comparison with selected item color in vertex shader as it should mean fewer compares
|
|
519
|
-
picking_vRGBcolor_Avalid.a = float(isVertexHighlighted(pickingColor));
|
|
430
|
+
fn picking_filterHighlightColor(color: vec4<f32>, objectIndex: i32) -> vec4<f32> {
|
|
431
|
+
if (picking.isActive != 0 || !picking_isObjectHighlighted(objectIndex)) {
|
|
432
|
+
return color;
|
|
520
433
|
}
|
|
521
|
-
}
|
|
522
434
|
|
|
523
|
-
|
|
524
|
-
|
|
525
|
-
|
|
526
|
-
|
|
527
|
-
index = uint(gl_InstanceID);
|
|
528
|
-
}
|
|
529
|
-
picking_vRGBcolor_Avalid.r = float(index % 255) / 255.0;
|
|
530
|
-
picking_vRGBcolor_Avalid.g = float((index / 255) % 255) / 255.0;
|
|
531
|
-
picking_vRGBcolor_Avalid.b = float((index / 255 / 255) %255) / 255.0;
|
|
435
|
+
let highLightAlpha = picking.highlightColor.a;
|
|
436
|
+
let blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
437
|
+
if (blendedAlpha == 0.0) {
|
|
438
|
+
return vec4<f32>(color.rgb, 0.0);
|
|
532
439
|
}
|
|
440
|
+
|
|
441
|
+
let highLightRatio = highLightAlpha / blendedAlpha;
|
|
442
|
+
let blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
443
|
+
return vec4<f32>(blendedRGB, blendedAlpha);
|
|
533
444
|
}
|
|
534
445
|
|
|
535
|
-
|
|
536
|
-
if (
|
|
537
|
-
|
|
446
|
+
fn picking_filterPickingColor(color: vec4<f32>, objectIndex: i32) -> vec4<f32> {
|
|
447
|
+
if (picking.isActive != 0 && objectIndex == INDEX_PICKING_INVALID_INDEX) {
|
|
448
|
+
discard;
|
|
538
449
|
}
|
|
450
|
+
return color;
|
|
539
451
|
}
|
|
540
452
|
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
picking_vRGBcolor_Avalid.rg = value;
|
|
544
|
-
}
|
|
453
|
+
fn picking_getPickingColor(objectIndex: i32) -> vec2<i32> {
|
|
454
|
+
return vec2<i32>(objectIndex, picking.batchIndex);
|
|
545
455
|
}
|
|
546
456
|
|
|
547
|
-
|
|
548
|
-
|
|
549
|
-
|
|
457
|
+
`,qs=`${St}
|
|
458
|
+
|
|
459
|
+
const int INDEX_PICKING_MODE_INSTANCE = 0;
|
|
460
|
+
const int INDEX_PICKING_MODE_CUSTOM = 1;
|
|
461
|
+
|
|
462
|
+
const int INDEX_PICKING_INVALID_INDEX = ${G}; // 2^32 - 1
|
|
463
|
+
|
|
464
|
+
flat out int picking_objectIndex;
|
|
465
|
+
|
|
466
|
+
/**
|
|
467
|
+
* Vertex shaders should call this function to set the object index.
|
|
468
|
+
* If using instance or vertex mode, argument will be ignored, 0 can be supplied.
|
|
469
|
+
*/
|
|
470
|
+
void picking_setObjectIndex(int objectIndex) {
|
|
471
|
+
switch (picking.indexMode) {
|
|
472
|
+
case INDEX_PICKING_MODE_INSTANCE:
|
|
473
|
+
picking_objectIndex = gl_InstanceID;
|
|
474
|
+
break;
|
|
475
|
+
case INDEX_PICKING_MODE_CUSTOM:
|
|
476
|
+
picking_objectIndex = objectIndex;
|
|
477
|
+
break;
|
|
550
478
|
}
|
|
551
479
|
}
|
|
552
|
-
|
|
480
|
+
`,Hs=`${St}
|
|
553
481
|
|
|
554
|
-
|
|
482
|
+
const int INDEX_PICKING_INVALID_INDEX = ${G}; // 2^32 - 1
|
|
555
483
|
|
|
556
|
-
|
|
484
|
+
flat in int picking_objectIndex;
|
|
485
|
+
|
|
486
|
+
/**
|
|
487
|
+
* Check if this vertex is highlighted (part of the selected batch and object)
|
|
488
|
+
*/
|
|
489
|
+
bool picking_isFragmentHighlighted() {
|
|
490
|
+
return
|
|
491
|
+
bool(picking.isHighlightActive) &&
|
|
492
|
+
picking.highlightedBatchIndex == picking.batchIndex &&
|
|
493
|
+
picking.highlightedObjectIndex == picking_objectIndex
|
|
494
|
+
;
|
|
495
|
+
}
|
|
496
|
+
|
|
497
|
+
/**
|
|
557
498
|
* Returns highlight color if this item is selected.
|
|
558
499
|
*/
|
|
559
500
|
vec4 picking_filterHighlightColor(vec4 color) {
|
|
560
501
|
// If we are still picking, we don't highlight
|
|
561
|
-
if (picking.isActive
|
|
502
|
+
if (bool(picking.isActive)) {
|
|
562
503
|
return color;
|
|
563
504
|
}
|
|
564
505
|
|
|
565
|
-
|
|
566
|
-
|
|
567
|
-
if (selected) {
|
|
568
|
-
// Blend in highlight color based on its alpha value
|
|
569
|
-
float highLightAlpha = picking.highlightColor.a;
|
|
570
|
-
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
571
|
-
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
572
|
-
|
|
573
|
-
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
574
|
-
return vec4(blendedRGB, blendedAlpha);
|
|
575
|
-
} else {
|
|
506
|
+
// If we are not highlighted, return color as is
|
|
507
|
+
if (!picking_isFragmentHighlighted()) {
|
|
576
508
|
return color;
|
|
577
509
|
}
|
|
510
|
+
|
|
511
|
+
// Blend in highlight color based on its alpha value
|
|
512
|
+
float highLightAlpha = picking.highlightColor.a;
|
|
513
|
+
float blendedAlpha = highLightAlpha + color.a * (1.0 - highLightAlpha);
|
|
514
|
+
float highLightRatio = highLightAlpha / blendedAlpha;
|
|
515
|
+
|
|
516
|
+
vec3 blendedRGB = mix(color.rgb, picking.highlightColor.rgb, highLightRatio);
|
|
517
|
+
return vec4(blendedRGB, blendedAlpha);
|
|
578
518
|
}
|
|
579
519
|
|
|
580
520
|
/*
|
|
581
521
|
* Returns picking color if picking enabled else unmodified argument.
|
|
582
522
|
*/
|
|
523
|
+
ivec4 picking_getPickingColor() {
|
|
524
|
+
// Assumes that colorAttachment0 is rg32int
|
|
525
|
+
// TODO? - we could render indices into a second color attachment and not mess with fragColor
|
|
526
|
+
return ivec4(picking_objectIndex, picking.batchIndex, 0u, 0u);
|
|
527
|
+
}
|
|
528
|
+
|
|
583
529
|
vec4 picking_filterPickingColor(vec4 color) {
|
|
584
530
|
if (bool(picking.isActive)) {
|
|
585
|
-
if (
|
|
531
|
+
if (picking_objectIndex == INDEX_PICKING_INVALID_INDEX) {
|
|
586
532
|
discard;
|
|
587
533
|
}
|
|
588
|
-
return picking_vRGBcolor_Avalid;
|
|
589
534
|
}
|
|
590
535
|
return color;
|
|
591
536
|
}
|
|
@@ -595,9 +540,11 @@ vec4 picking_filterPickingColor(vec4 color) {
|
|
|
595
540
|
* highlight color if this item is selected, otherwise unmodified argument.
|
|
596
541
|
*/
|
|
597
542
|
vec4 picking_filterColor(vec4 color) {
|
|
598
|
-
vec4
|
|
599
|
-
|
|
543
|
+
vec4 outColor = color;
|
|
544
|
+
outColor = picking_filterHighlightColor(outColor);
|
|
545
|
+
outColor = picking_filterPickingColor(outColor);
|
|
546
|
+
return outColor;
|
|
600
547
|
}
|
|
601
|
-
`,
|
|
548
|
+
`,Se={...Lt,name:"picking",source:Xs,vs:qs,fs:Hs};var jn={...Lt,name:"picking",source:Se.source,vs:$t.vs,fs:$t.fs};var Le=class{device;framebuffer=null;shaderInputs;constructor(t,e){this.device=t,this.shaderInputs=e}destroy(){this.framebuffer?.destroy()}getFramebuffer(){return this.framebuffer||(this.framebuffer=this.device.createFramebuffer({colorAttachments:["rgba8unorm"],depthStencilAttachment:"depth24plus"})),this.framebuffer}clearPickState(){this.shaderInputs.setProps({picking:{highlightedObjectColor:null}})}beginRenderPass(){let t=this.getFramebuffer();return t.resize(this.device.getCanvasContext().getDevicePixelSize()),this.shaderInputs.setProps({picking:{isActive:!0}}),this.device.beginRenderPass({framebuffer:t,clearColor:[0,0,0,0],clearDepth:1})}updatePickState(t){let e=this.getFramebuffer(),[n,r]=this.getPickPosition(t),o=[...this.device.readPixelsToArrayWebGL(e,{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(t){let e=this.device.getCanvasContext().cssToDevicePixels(t),n=e.x+Math.floor(e.width/2),r=e.y+Math.floor(e.height/2);return[n,r]}};var Gn=R(rt(),1),Un=Gn.picking;var Ws=z;return tr(Vt);})();
|
|
602
549
|
return __exports__;
|
|
603
550
|
});
|