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