@babylonjs/viewer
Version:
The Babylon Viewer aims to simplify a specific but common Babylon.js use case: loading, viewing, and interacting with a 3D model.
3 lines (2 loc) • 38.6 kB
JavaScript
import{T as e,a as t,b as i,c as s,d as n,e as a,W as r}from"./webgpuEngine.pure-BHfRCzkH.esm.min.js";import"./clearQuad.vertex-BvejM21h.esm.min.js";import"./clearQuad.fragment-BWDslFTn.esm.min.js";import{a7 as o,cH as u,bk as h,O as d,V as l,aD as p,M as _,a as c,A as m,C as f,w as g,y as T,cI as b,cn as A}from"./index-BPURObVq.esm.min.js";import"./instancesVertex-BGTenKaI.esm.min.js";import"./bakedVertexAnimation-p4-Xji_j.esm.min.js";import"./instancesDeclaration-DL-jEUgP.esm.min.js";import"./helperFunctions-T6LSXWWf.esm.min.js";import"./fresnelFunction-55bywfOj.esm.min.js";import"./meshUboDeclaration-CnWBjnGc.esm.min.js";import"./sceneUboDeclaration-BlOB2RUY.esm.min.js";import"./decalFragment-DyTBBYbA.esm.min.js";import{R as y}from"./renderTargetWrapper-BsxrLXvO.esm.min.js";import{e as E,d as R,f as x,A as v}from"./spatialWebAudioUpdaterComponent-LOlF6N8J.esm.min.js";import"./sphericalPolynomial.pure-CsRKkAN3.esm.min.js";import"./textureLoaderManager-CGf6Ha4H.esm.min.js";let w=!1;!function(){if(w)return;w=!0;const e=(()=>{const e=new Uint8Array(4);return!!((new Uint32Array(e.buffer)[0]=1)&e[0])})();Object.defineProperty(o.prototype,"effectiveByteStride",{get:function(){return this._alignedBuffer&&this._alignedBuffer.byteStride||this.byteStride},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"effectiveByteOffset",{get:function(){return this._alignedBuffer?0:this.byteOffset},enumerable:!0,configurable:!0}),Object.defineProperty(o.prototype,"effectiveBuffer",{get:function(){return this._alignedBuffer&&this._alignedBuffer.getBuffer()||this._buffer.getBuffer()},enumerable:!0,configurable:!0}),o.prototype._rebuild=function(){this._buffer?._rebuild(),this._alignedBuffer?._rebuild()},o.prototype.dispose=function(){this._ownsBuffer&&this._buffer.dispose(),this._alignedBuffer?.dispose(),this._alignedBuffer=void 0,this._isDisposed=!0},o.prototype.getWrapperBuffer=function(){return this._alignedBuffer||this._buffer},o.prototype._alignBuffer=function(){const t=this._buffer.getData();if(!this.engine._features.forceVertexBufferStrideAndOffsetMultiple4Bytes||this.byteStride%4==0&&this.byteOffset%4==0||!t)return;const i=u(this.type),s=this.byteStride+3&-4,n=s/i,a=this._maxVerticesCount,r=a*s/i;let d,l;if(Array.isArray(t)){const e=new Float32Array(t);d=new DataView(e.buffer,e.byteOffset,e.byteLength)}else d=ArrayBuffer.isView(t)?new DataView(t.buffer,t.byteOffset,t.byteLength):new DataView(t,0,t.byteLength);l=this.type===o.BYTE?new Int8Array(r):this.type===o.UNSIGNED_BYTE?new Uint8Array(r):this.type===o.SHORT?new Int16Array(r):this.type===o.UNSIGNED_SHORT||this.type===o.HALF_FLOAT?new Uint16Array(r):this.type===o.INT?new Int32Array(r):this.type===o.UNSIGNED_INT?new Uint32Array(r):new Float32Array(r);const p=this.getSize();let _=this.byteOffset;for(let t=0;t<a;++t){for(let i=0;i<p;++i)switch(this.type){case o.BYTE:l[t*n+i]=d.getInt8(_+i);break;case o.UNSIGNED_BYTE:l[t*n+i]=d.getUint8(_+i);break;case o.SHORT:l[t*n+i]=d.getInt16(_+2*i,e);break;case o.UNSIGNED_SHORT:case o.HALF_FLOAT:l[t*n+i]=d.getUint16(_+2*i,e);break;case o.INT:l[t*n+i]=d.getInt32(_+4*i,e);break;case o.UNSIGNED_INT:l[t*n+i]=d.getUint32(_+4*i,e);break;case o.FLOAT:l[t*n+i]=d.getFloat32(_+4*i,e)}_+=this.byteStride}this._alignedBuffer?.dispose(),this._alignedBuffer=new h(this.engine,l,!1,s,!1,this.getIsInstanced(),!0,this.instanceDivisor,(this._label??"VertexBuffer")+"_aligned")}}();const M=[];new d;class S{static get Instances(){return M}get onNodeAddedObservable(){return this._onNodeAddedObservable}get onNodeRemovedObservable(){return this._onNodeRemovedObservable}get onDisposeObservable(){return this._onDisposeObservable}constructor(e){this._mainBuses=new Set,this._sounds=new Set,this._soundsArray=null,this._nodes=new Set,this._defaultMainBus=null,this._parameterRampDuration=.01,this._onNodeAddedObservable=new d,this._onNodeRemovedObservable=new d,this._onDisposeObservable=new d,M.push(this),"number"==typeof e.parameterRampDuration&&(this.parameterRampDuration=e.parameterRampDuration)}get defaultMainBus(){return 0===this._mainBuses.size?null:(this._defaultMainBus||(this._defaultMainBus=Array.from(this._mainBuses)[0]),this._defaultMainBus)}get parameterRampDuration(){return this._parameterRampDuration}set parameterRampDuration(e){this._parameterRampDuration=Math.max(0,e)}get sounds(){return this._soundsArray||(this._soundsArray=Array.from(this._sounds)),this._soundsArray}get nodes(){return this._nodes}dispose(){M.includes(this)&&M.splice(M.indexOf(this),1);const e=this._nodes.values();for(let t=e.next();!t.done;t=e.next())t.value.dispose();this._mainBuses.clear(),this._nodes.clear(),this._sounds.clear(),this._disposeSoundsArray(),this._defaultMainBus=null,this._onDisposeObservable.notifyObservers(this),this._onDisposeObservable.clear(),this._onNodeAddedObservable.clear(),this._onNodeRemovedObservable.clear()}unlockAsync(){return this.resumeAsync()}_addMainBus(e){this._mainBuses.add(e),this._addNode(e)}_removeMainBus(e){this._mainBuses.delete(e),this._defaultMainBus=null,this._removeNode(e)}_addNode(e){this._nodes.add(e),this._onNodeAddedObservable.notifyObservers(e)}_removeNode(e){this._nodes.delete(e),this._onNodeRemovedObservable.notifyObservers(e)}_addSound(e){this._disposeSoundsArray(),this._sounds.add(e),this._addNode(e)}_removeSound(e){this._disposeSoundsArray(),this._sounds.delete(e),this._removeNode(e)}_onSoundPlaybackStateChanged(){}_disposeSoundsArray(){this._soundsArray&&(this._soundsArray.length=0,this._soundsArray=null)}}const O={position:l.Zero(),rotation:l.Zero(),rotationQuaternion:new p};class U{}class C extends U{constructor(){super(),this._attacherComponent=null,this._attacherComponent=new E(this)}get isAttached(){return null!==this._attacherComponent&&this._attacherComponent.isAttached}get attachedNode(){return this._attacherComponent?.sceneNode??null}attach(e,t=!1,i=3){this._attacherComponent||(this._attacherComponent=new E(this)),this._attacherComponent.attach(e,t,i)}detach(){this._attacherComponent?.detach()}dispose(){this._attacherComponent?.dispose(),this._attacherComponent=null}setOptions(e){void 0!==e.listenerMinUpdateTime&&(this.minUpdateTime=e.listenerMinUpdateTime),e.listenerPosition&&(this.position=e.listenerPosition.clone()),e.listenerRotationQuaternion?this.rotationQuaternion=e.listenerRotationQuaternion.clone():e.listenerRotation?this.rotation=e.listenerRotation.clone():this.rotationQuaternion=O.rotationQuaternion.clone(),this.update()}}const N=_.Zero(),I=new p,D=l.Zero(),P=l.Zero();function B(e,t,i){const s=e._audioContext.listener;return s.forwardX&&s.forwardY&&s.forwardZ&&s.positionX&&s.positionY&&s.positionZ&&s.upX&&s.upY&&s.upZ?new L(e,t,i):new G(e,t,i)}class F extends C{constructor(e,t,i){super(),this._lastPosition=l.Zero(),this._lastRotation=l.Zero(),this._lastRotationQuaternion=new p,this.position=l.Zero(),this.rotation=l.Zero(),this.rotationQuaternion=new p,this._listener=e._audioContext.listener,this.engine=e,this._updaterComponent=new x(this,t,i)}dispose(){super.dispose(),this._updaterComponent.dispose(),this._updaterComponent=null}get minUpdateTime(){return this._updaterComponent.minUpdateTime}set minUpdateTime(e){this._updaterComponent.minUpdateTime=e}update(){this.isAttached?this._attacherComponent?.update():(this._updatePosition(),this._updateRotation())}_updatePosition(){this._lastPosition.equalsWithEpsilon(this.position)||(this._setWebAudioPosition(this.position),this._lastPosition.copyFrom(this.position))}_updateRotation(){if(this._lastRotationQuaternion.equalsWithEpsilon(this.rotationQuaternion)){if(this._lastRotation.equalsWithEpsilon(this.rotation))return;p.FromEulerAnglesToRef(this.rotation.x,this.rotation.y,this.rotation.z,I),this._lastRotation.copyFrom(this.rotation)}else I.copyFrom(this.rotationQuaternion),this._lastRotationQuaternion.copyFrom(this.rotationQuaternion);_.FromQuaternionToRef(I,N),l.TransformNormalToRef(l.RightHandedForwardReadOnly,N,D),l.TransformNormalToRef(l.Up(),N,P),this._setWebAudioOrientation(D,P)}}class L extends F{constructor(e,t,i){super(e,t,i);const s=e._audioContext.listener;this._forwardX=new R(e,s.forwardX),this._forwardY=new R(e,s.forwardY),this._forwardZ=new R(e,s.forwardZ),this._positionX=new R(e,s.positionX),this._positionY=new R(e,s.positionY),this._positionZ=new R(e,s.positionZ),this._upX=new R(e,s.upX),this._upY=new R(e,s.upY),this._upZ=new R(e,s.upZ)}_setWebAudioPosition(e){this.isAttached&&(this._positionX.isRamping||this._positionY.isRamping||this._positionZ.isRamping)||(this._positionX.targetValue=e.x,this._positionY.targetValue=e.y,this._positionZ.targetValue=e.z)}_setWebAudioOrientation(e,t){this.isAttached&&(this._forwardX.isRamping||this._forwardY.isRamping||this._forwardZ.isRamping||this._upX.isRamping||this._upY.isRamping||this._upZ.isRamping)||(this._forwardX.targetValue=e.x,this._forwardY.targetValue=e.y,this._forwardZ.targetValue=e.z,this._upX.targetValue=t.x,this._upY.targetValue=t.y,this._upZ.targetValue=t.z)}}class G extends F{_setWebAudioPosition(e){this._listener.setPosition(e.x,e.y,e.z)}_setWebAudioOrientation(e,t){this._listener.setOrientation(e.x,e.y,e.z,t.x,t.y,t.z)}}class X extends v{constructor(e){super(e,1)}}class H extends X{constructor(e){super(e),this._setGainNode(new GainNode(e._audioContext))}dispose(){super.dispose(),this._volume.dispose(),this._gainNode.disconnect(),this._destinationNode.disconnect()}get _inNode(){return this._gainNode}set _inNode(e){this._gainNode!==e&&this._setGainNode(e)}get volume(){return this._volume.targetValue}set volume(e){this._volume.targetValue=e}get _destinationNode(){return this.engine._audioDestination}getClassName(){return"_WebAudioMainOut"}setVolume(e,t=null){this._volume.setTargetValue(e,t)}_setGainNode(e){this._gainNode!==e&&(this._gainNode?.disconnect(),e.connect(this._destinationNode),this._volume=new R(this.engine,e.gain),this._gainNode=e)}}class k{constructor(e,t){this._button=null,this._enabled=!0,this._style=null,this._onStateChanged=()=>{this._button&&("running"===this._engine.state?this._hide():this._show())},this._engine=e;const i=t||c.LastCreatedEngine?.getInputElement()?.parentElement||document.body,s=(i?.offsetTop||0)+20;this._style=document.createElement("style"),this._style.appendChild(document.createTextNode(`.babylonUnmute{position:absolute;top:${s}px;margin-left:20px;height:40px;width:60px;background-color:rgba(51,51,51,0.7);background-image:url("data:image/svg+xml;charset=UTF-8,%3Csvg%20version%3D%221.1%22%20xmlns%3D%22http%3A%2F%2Fwww.w3.org%2F2000%2Fsvg%22%20width%3D%2239%22%20height%3D%2232%22%20viewBox%3D%220%200%2039%2032%22%3E%3Cpath%20fill%3D%22white%22%20d%3D%22M9.625%2018.938l-0.031%200.016h-4.953q-0.016%200-0.031-0.016v-12.453q0-0.016%200.031-0.016h4.953q0.031%200%200.031%200.016v12.453zM12.125%207.688l8.719-8.703v27.453l-8.719-8.719-0.016-0.047v-9.938zM23.359%207.875l1.406-1.406%204.219%204.203%204.203-4.203%201.422%201.406-4.219%204.219%204.219%204.203-1.484%201.359-4.141-4.156-4.219%204.219-1.406-1.422%204.219-4.203z%22%3E%3C%2Fpath%3E%3C%2Fsvg%3E");background-size:80%;background-repeat:no-repeat;background-position:center;background-position-y:4px;border:none;outline:none;transition:transform 0.125s ease-out;cursor:pointer;z-index:9999;}.babylonUnmute:hover{transform:scale(1.05)}`)),document.head.appendChild(this._style),this._button=document.createElement("button"),this._button.className="babylonUnmute",this._button.id="babylonUnmuteButton",this._button.addEventListener("click",()=>{this._engine.unlockAsync()}),i.appendChild(this._button),this._engine.stateChangedObservable.add(this._onStateChanged)}dispose(){this._button?.remove(),this._button=null,this._style?.remove(),this._style=null,this._engine.stateChangedObservable.removeCallback(this._onStateChanged)}get enabled(){return this._enabled}set enabled(e){this._enabled=e,e?"running"!==this._engine.state&&this._show():this._hide()}_show(){this._button&&this._enabled&&(this._button.style.display="block")}_hide(){this._button&&(this._button.style.display="none")}}const W={aac:"audio/aac",ac3:"audio/ac3",flac:"audio/flac",m4a:"audio/mp4",mp3:'audio/mpeg; codecs="mp3"',mp4:"audio/mp4",ogg:'audio/ogg; codecs="vorbis"',wav:"audio/wav",webm:'audio/webm; codecs="vorbis"'};class Y extends S{constructor(e={}){super(e),this._audioContextStarted=!1,this._destinationNode=null,this._invalidFormats=new Set,this._isUpdating=!1,this._listener=null,this._listenerAutoUpdate=!0,this._listenerMinUpdateTime=0,this._pauseCalled=!1,this._resumeOnInteraction=!0,this._resumeOnPause=!0,this._resumeOnPauseRetryInterval=1e3,this._resumeOnPauseTimerId=null,this._resumePromise=null,this._silentHtmlAudio=null,this._unmuteUI=null,this._updateObservable=null,this._validFormats=new Set,this._volume=1,this._isUsingOfflineAudioContext=!1,this.isReadyPromise=new Promise(e=>{this._resolveIsReadyPromise=e}),this.stateChangedObservable=new d,this.userGestureObservable=new d,this._initAudioContextAsync=async()=>{this._audioContext.addEventListener("statechange",this._onAudioContextStateChange),this._mainOut=new H(this),this._mainOut.volume=this._volume,await this.createMainBusAsync("default")},this._onAudioContextStateChange=()=>{"running"===this.state&&(clearInterval(this._resumeOnPauseTimerId),this._audioContextStarted=!0,this._resumePromise=null),"suspended"!==this.state&&"interrupted"!==this.state||this._audioContextStarted&&this._resumeOnPause&&!this._pauseCalled&&(clearInterval(this._resumeOnPauseTimerId),this._resumeOnPauseTimerId=setInterval(()=>{this.resumeAsync()},this._resumeOnPauseRetryInterval)),this.stateChangedObservable.notifyObservers(this.state)},this._onUserGestureAsync=async()=>{if(this._resumeOnInteraction&&await this._audioContext.resume(),!this._silentHtmlAudio){this._silentHtmlAudio=document.createElement("audio");const e=this._silentHtmlAudio;e.controls=!1,e.preload="auto",e.loop=!0,e.src="data:audio/wav;base64,UklGRjAAAABXQVZFZm10IBAAAAABAAEAgLsAAAB3AQACABAAZGF0YQwAAAAAAAEA/v8CAP//AQA=",e.play().then(()=>e.pause(),()=>{})}this.userGestureObservable.notifyObservers()},this._startUpdating=()=>{if(!this._isUpdating)if(this._isUpdating=!0,"running"===this.state)this._update();else{const e=()=>{"running"===this.state&&(this._update(),this.stateChangedObservable.removeCallback(e))};this.stateChangedObservable.add(e)}},this._update=()=>{this._updateObservable?.hasObservers()?(this._updateObservable.notifyObservers(),requestAnimationFrame(this._update)):this._isUpdating=!1},"boolean"==typeof e.listenerAutoUpdate&&(this._listenerAutoUpdate=e.listenerAutoUpdate),"number"==typeof e.listenerMinUpdateTime&&(this._listenerMinUpdateTime=e.listenerMinUpdateTime),this._volume=e.volume??1,e.audioContext?(this._isUsingOfflineAudioContext=e.audioContext instanceof OfflineAudioContext,this._audioContext=e.audioContext):this._audioContext=new AudioContext,e.disableDefaultUI||(this._unmuteUI=new k(this,e.defaultUIParentElement))}async _initAsync(e){this._resumeOnInteraction="boolean"!=typeof e.resumeOnInteraction||e.resumeOnInteraction,this._resumeOnPause="boolean"!=typeof e.resumeOnPause||e.resumeOnPause,this._resumeOnPauseRetryInterval=e.resumeOnPauseRetryInterval??1e3,document.addEventListener("click",this._onUserGestureAsync),await this._initAudioContextAsync(),function(e){return e.listenerEnabled||void 0!==e.listenerMinUpdateTime||void 0!==e.listenerPosition||void 0!==e.listenerRotation||void 0!==e.listenerRotationQuaternion}(e)&&(this._listener=B(this,this._listenerAutoUpdate,this._listenerMinUpdateTime),this._listener.setOptions(e)),this._resolveIsReadyPromise()}get currentTime(){return this._audioContext.currentTime??0}get _inNode(){return this._audioContext.destination}get mainOut(){return this._mainOut}get listener(){return this._listener??(this._listener=B(this,this._listenerAutoUpdate,this._listenerMinUpdateTime))}get state(){return this._isUsingOfflineAudioContext?"running":this._audioContext.state}get volume(){return this._volume}set volume(e){this._volume!==e&&(this._volume=e,this._mainOut&&(this._mainOut.volume=e))}get _audioDestination(){return this._destinationNode?this._destinationNode:this._destinationNode=this._audioContext.destination}set _audioDestination(e){this._destinationNode=e}get _unmuteUIEnabled(){return!!this._unmuteUI&&this._unmuteUI.enabled}set _unmuteUIEnabled(e){this._unmuteUI&&(this._unmuteUI.enabled=e)}async createBusAsync(e,t={}){const i=new((await import("./webAudioBus-vHdCuDid.esm.min.js"))._WebAudioBus)(e,this,t);return await i._initAsync(t),i}async createMainBusAsync(e,t={}){const i=new((await import("./webAudioMainBus-D-CQkjn8.esm.min.js"))._WebAudioMainBus)(e,this);return await i._initAsync(t),i}async createMicrophoneSoundSourceAsync(e,t){let i;try{i=await navigator.mediaDevices.getUserMedia({audio:!0})}catch(e){throw new Error("Unable to access microphone: "+e,{cause:e})}return await this.createSoundSourceAsync(e,new MediaStreamAudioSourceNode(this._audioContext,{mediaStream:i}),{outBusAutoDefault:!1,mediaStreamSinkEnabled:!1,stopMediaStreamTracksOnDispose:!0,...t})}async createSoundAsync(e,t,i={}){const s=new((await import("./webAudioStaticSound-MIX2pABC.esm.min.js"))._WebAudioStaticSound)(e,this,i);return await s._initAsync(t,i),s}async createSoundBufferAsync(e,t={}){const i=new((await import("./webAudioStaticSound-MIX2pABC.esm.min.js"))._WebAudioStaticSoundBuffer)(this);return await i._initAsync(e,t),i}async createSoundSourceAsync(e,t,i={}){const s=new((await import("./webAudioSoundSource-CbegW_An.esm.min.js"))._WebAudioSoundSource)(e,t,this,i);return await s._initAsync(i),s}async createStreamingSoundAsync(e,t,i={}){const s=new((await import("./webAudioStreamingSound-G95NHMdc.esm.min.js"))._WebAudioStreamingSound)(e,this,i);return await s._initAsync(t,i),s}dispose(){super.dispose(),this._listener?.dispose(),this._listener=null,"closed"===this._audioContext.state||this._isUsingOfflineAudioContext||this._audioContext.close(),document.removeEventListener("click",this._onUserGestureAsync),this._audioContext.removeEventListener("statechange",this._onAudioContextStateChange),this._silentHtmlAudio?.remove(),this._updateObservable?.clear(),this._updateObservable=null,this._unmuteUI?.dispose(),this._unmuteUI=null,this.stateChangedObservable.clear()}flagInvalidFormat(e){this._invalidFormats.add(e)}isFormatValid(e){if(this._validFormats.has(e))return!0;if(this._invalidFormats.has(e))return!1;const t=W[e];if(void 0===t)return!1;return""===(new Audio).canPlayType(t)?(this._invalidFormats.add(e),!1):(this._validFormats.add(e),!0)}async pauseAsync(){await this._audioContext.suspend(),this._pauseCalled=!0}resumeAsync(){return this._pauseCalled=!1,this._resumePromise||(this._resumePromise=this._audioContext.resume(),this.stateChangedObservable.notifyObservers(this.state)),this._resumePromise}setVolume(e,t=null){if(!this._mainOut)throw new Error("Main output not initialized yet.");this._mainOut.setVolume(e,t)}_addMainBus(e){super._addMainBus(e)}_removeMainBus(e){super._removeMainBus(e)}_addNode(e){super._addNode(e)}_removeNode(e){super._removeNode(e)}_addSound(e){super._addSound(e)}_removeSound(e){super._removeSound(e)}_onSoundPlaybackStateChanged(){if(!this._silentHtmlAudio)return;const e=this.sounds.some(e=>3===e.state||2===e.state||0===e.state);e&&this._silentHtmlAudio.paused?this._silentHtmlAudio.play().catch(()=>{}):e||this._silentHtmlAudio.paused||this._silentHtmlAudio.pause()}_addUpdateObserver(e){this._updateObservable||(this._updateObservable=new d),this._updateObservable.add(e),this._startUpdating()}_removeUpdateObserver(e){this._updateObservable&&this._updateObservable.removeCallback(e)}}class V{get masterGain(){return this._masterGain}set masterGain(e){this._masterGain=this._v2.mainOut._inNode=e}get useCustomUnlockedButton(){return this._useCustomUnlockedButton}set useCustomUnlockedButton(e){this._useCustomUnlockedButton=e,this._v2._unmuteUIEnabled=!e}get audioContext(){return"running"===this._v2.state&&this._triggerRunningStateAsync(),this._v2._audioContext}constructor(e=null,t=null,i=null){this._tryToRun=!1,this._useCustomUnlockedButton=!1,this.canUseWebAudio=!0,this.WarnedWebAudioUnsupported=!1,this.isMP3supported=!1,this.isOGGsupported=!1,this.unlocked=!1,this.onAudioUnlockedObservable=new d,this.onAudioLockedObservable=new d;const s=new Y({audioContext:t||void 0,defaultUIParentElement:e?.parentElement?e.parentElement:void 0});s._unmuteUIEnabled=!1,this._masterGain=new GainNode(s._audioContext),s._audioDestination=i,s.stateChangedObservable.add(e=>{"running"===e?(this.unlocked=!0,this.onAudioUnlockedObservable.notifyObservers(this)):(this.unlocked=!1,this.onAudioLockedObservable.notifyObservers(this))}),s._initAsync({resumeOnInteraction:!1}).then(()=>{const e=s.defaultMainBus._outNode;e&&(e.disconnect(s.mainOut._inNode),e.connect(this._masterGain)),s.mainOut._inNode=this._masterGain,s.stateChangedObservable.notifyObservers(s.state)}),this.isMP3supported=s.isFormatValid("mp3"),this.isOGGsupported=s.isFormatValid("ogg"),this._v2=s}lock(){this._v2._audioContext.suspend(),this._useCustomUnlockedButton||(this._v2._unmuteUIEnabled=!0)}unlock(){"running"!==this._v2._audioContext?.state?this._triggerRunningStateAsync():this.unlocked||(this.unlocked=!0,this.onAudioUnlockedObservable.notifyObservers(this))}_resumeAudioContextOnStateChange(){this._v2._audioContext?.addEventListener("statechange",()=>{this.unlocked&&"running"!==this._v2._audioContext?.state&&this._resumeAudioContextAsync()},{once:!0,passive:!0,signal:AbortSignal.timeout(3e3)})}_resumeAudioContextAsync(){return this._v2._isUsingOfflineAudioContext?Promise.resolve():("suspended"!==this._v2._audioContext.state||this._useCustomUnlockedButton||(this._v2._unmuteUIEnabled=!0),this._v2._audioContext.resume())}dispose(){this._v2.dispose(),this.onAudioUnlockedObservable.clear(),this.onAudioLockedObservable.clear()}getGlobalVolume(){return this.masterGain.gain.value}setGlobalVolume(e){this.masterGain.gain.value=e}connectToAnalyser(e){this._connectedAnalyser&&this._connectedAnalyser.stopDebugCanvas(),this._connectedAnalyser=e,this.masterGain.disconnect(),this._connectedAnalyser.connectAudioNodes(this.masterGain,this._v2._audioContext.destination)}async _triggerRunningStateAsync(){this._tryToRun?this._v2._audioContext.resume():(this._tryToRun=!0,await this._resumeAudioContextAsync(),this._tryToRun=!1,this.unlocked=!0,this.onAudioUnlockedObservable.notifyObservers(this))}}let Q=!1;Q||(Q=!0,m.AudioEngineFactory=(e,t,i)=>new V(e,t,i));let j=!1;j||(j=!0,e.prototype.setAlphaMode=function(e,t=!1,i=0){const s=this._alphaState._alphaBlend[i];if(this._alphaMode[i]===e&&(e===f.ALPHA_DISABLE&&!s||e!==f.ALPHA_DISABLE&&s)){if(!t){const t=e===f.ALPHA_DISABLE;this.depthCullingState.depthMask!==t&&(this.setDepthWrite(t),this._cacheRenderPipeline.setDepthWriteEnabled(t))}return}const n=e===f.ALPHA_DISABLE;this._alphaState.setAlphaBlend(!n,i),this._alphaState.setAlphaMode(e,i),t||(this.setDepthWrite(n),this._cacheRenderPipeline.setDepthWriteEnabled(n)),this._alphaMode[i]=e,this._cacheRenderPipeline.setAlphaBlendEnabled(this._alphaState._alphaBlend,this._alphaState._numTargetEnabled),this._cacheRenderPipeline.setAlphaBlendFactors(this._alphaState._blendFunctionParameters,this._alphaState._blendEquationParameters)},e.prototype.setAlphaEquation=function(e,t=0){m.prototype.setAlphaEquation.call(this,e,t),this._cacheRenderPipeline.setAlphaBlendFactors(this._alphaState._blendFunctionParameters,this._alphaState._blendEquationParameters)});let Z=!1;!function(){if(Z)return;Z=!0;const i=new WeakMap;e.prototype.getAlphaToCoverage=function(){return i.get(this)??!1},e.prototype.setAlphaToCoverage=function(e){const t=this._cacheRenderPipeline;(i.get(this)??!1)===e&&t._alphaToCoverageEnabled===e||(i.set(this,e),this._cacheRenderPipeline.setAlphaToCoverage(e))};const s=t.prototype,n=s._buildRenderPipelineDescriptor;s._buildRenderPipelineDescriptor=function(e,t,i){const s=n.call(this,e,t,i);return s.multisample.alphaToCoverageEnabled=this._alphaToCoverageEnabled&&i>1,s}}();let z=!1;!function(){function t(e,t,i,s){let n,a=1;s===f.TEXTURETYPE_FLOAT?n=new Float32Array(t*i*4):s===f.TEXTURETYPE_HALF_FLOAT?(n=new Uint16Array(t*i*4),a=15360):n=s===f.TEXTURETYPE_UNSIGNED_INTEGER?new Uint32Array(t*i*4):new Uint8Array(t*i*4);for(let s=0;s<t;s++)for(let r=0;r<i;r++){const i=3*(r*t+s),o=4*(r*t+s);n[o+0]=e[i+0],n[o+1]=e[i+1],n[o+2]=e[i+2],n[o+3]=a}return n}z||(z=!0,e.prototype.createRawTexture=function(e,t,i,s,n,a,r,o=null,u=f.TEXTURETYPE_UNSIGNED_BYTE,h=0,d=!1,l){const p=new g(this,3);return p.baseWidth=t,p.baseHeight=i,p.width=t,p.height=i,p.format=s,p.generateMipMaps=n,p.samplingMode=r,p.invertY=a,p._compression=o,p.type=u,p._creationFlags=h,p._useSRGBBuffer=d,this._doNotHandleContextLost||(p._bufferView=e),this._textureHelper.updateMipLevelCountForInternalTexture(p,l),this._textureHelper.createGPUTextureForInternalTexture(p,t,i,void 0,h),this.updateRawTexture(p,e,s,a,o,u,d),this._internalTexturesCache.push(p),p},e.prototype.updateRawTexture=function(e,i,s,n,a=null,r=f.TEXTURETYPE_UNSIGNED_BYTE,o=!1,u){if(e){if(this._doNotHandleContextLost||(e._bufferView=i,e.invertY=n,e._compression=a,e._useSRGBBuffer=o,void 0!==u&&i&&(e._bufferViewArray||(e._bufferViewArray=new Array(e.mipLevelCount)),e._bufferViewArray[u]=i)),i){const a=e._hardwareTexture;s===f.TEXTUREFORMAT_RGB&&(i=t(i,e.width,e.height,r));const o=new Uint8Array(i.buffer,i.byteOffset,i.byteLength),h=Math.max(1,e.width>>(u??0)),d=Math.max(1,e.height>>(u??0));this._textureHelper.updateTexture(o,e,h,d,e.depth,a.format,0,u??0,n,!1,0,0),e.generateMipMaps&&!u&&this._generateMipmaps(e,this._uploadEncoder)}e.isReady=!0}},e.prototype.createRawCubeTexture=function(e,t,i,s,n,a,r,o=null){const u=new g(this,8);if(s!==f.TEXTURETYPE_FLOAT||this._caps.textureFloatLinearFiltering?s!==f.TEXTURETYPE_HALF_FLOAT||this._caps.textureHalfFloatLinearFiltering?s!==f.TEXTURETYPE_FLOAT||this._caps.textureFloatRender?s!==f.TEXTURETYPE_HALF_FLOAT||this._caps.colorBufferFloat||(n=!1,T.Warn("Render to half float textures is not supported. Mipmap generation forced to false.")):(n=!1,T.Warn("Render to float textures is not supported. Mipmap generation forced to false.")):(n=!1,r=f.TEXTURE_NEAREST_SAMPLINGMODE,T.Warn("Half float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.")):(n=!1,r=f.TEXTURE_NEAREST_SAMPLINGMODE,T.Warn("Float texture filtering is not supported. Mipmap generation and sampling mode are forced to false and TEXTURE_NEAREST_SAMPLINGMODE, respectively.")),u.isCube=!0,u._originalFormat=i,u.format=i===f.TEXTUREFORMAT_RGB?f.TEXTUREFORMAT_RGBA:i,u.type=s,u.generateMipMaps=n,u.width=t,u.height=t,u.samplingMode=r,this._doNotHandleContextLost||(u._bufferViewArray=e),u.invertY=a,u._compression=o,u._cachedWrapU=f.TEXTURE_CLAMP_ADDRESSMODE,u._cachedWrapV=f.TEXTURE_CLAMP_ADDRESSMODE,this._textureHelper.createGPUTextureForInternalTexture(u),i===f.TEXTUREFORMAT_RGB){u._hardwareTexture._originalFormatIsRGB=!0}return e&&this.updateRawCubeTexture(u,e,i,s,a,o),u.isReady=!0,u},e.prototype.updateRawCubeTexture=function(e,i,s,n,a,r=null){e._bufferViewArray=i,e.invertY=a,e._compression=r;const o=e._hardwareTexture,u=o._originalFormatIsRGB,h=[0,2,4,1,3,5],d=[];for(let s=0;s<i.length;++s){let a=i[h[s]];u&&(a=t(a,e.width,e.height,n)),d.push(new Uint8Array(a.buffer,a.byteOffset,a.byteLength))}this._textureHelper.updateCubeTextures(d,e,e.width,e.height,o.format,a,!1,0,0),e.generateMipMaps&&this._generateMipmaps(e,this._uploadEncoder),e.isReady=!0},e.prototype.createRawCubeTextureFromUrl=function(e,i,s,n,a,r,o,u,h=null,d=null,l=f.TEXTURE_TRILINEAR_SAMPLINGMODE,p=!1){const _=this.createRawCubeTexture(null,s,n,a,!r,p,l,null);i?.addPendingData(_),_.url=e,_.isReady=!1,this._internalTexturesCache.push(_);const c=(e,t)=>{i?.removePendingData(_),d&&e&&d(e.status+" "+e.statusText,t)},m=async e=>{const s=o(e);if(!s)return;const r=s instanceof Promise?await s:s,d=_.width;if(u){const e=n===f.TEXTUREFORMAT_RGB,i=u(r),s=_._hardwareTexture,o=[0,1,2,3,4,5];for(let n=0;n<i.length;n++){const r=d>>n,u=[];for(let s=0;s<6;s++){let h=i[n][o[s]];e&&(h=t(h,r,r,a)),u.push(new Uint8Array(h.buffer,h.byteOffset,h.byteLength))}this._textureHelper.updateCubeTextures(u,_,r,r,s.format,p,!1,0,0)}}else this.updateRawCubeTexture(_,r,n,a,p);_.isReady=!0,i?.removePendingData(_),h&&h()};return this._loadFile(e,e=>{m(e).catch(e=>{c(void 0,e)})},void 0,i?.offlineProvider,!0,c),_},e.prototype.createRawTexture3D=function(e,t,i,s,n,a,r,o,u=null,h=f.TEXTURETYPE_UNSIGNED_BYTE,d=0){const l=new g(this,10);return l.baseWidth=t,l.baseHeight=i,l.baseDepth=s,l.width=t,l.height=i,l.depth=s,l.format=n,l.type=h,l.generateMipMaps=a,l.samplingMode=o,l.is3D=!0,l._creationFlags=d,this._doNotHandleContextLost||(l._bufferView=e),this._textureHelper.createGPUTextureForInternalTexture(l,t,i,void 0,d),this.updateRawTexture3D(l,e,n,r,u,h),this._internalTexturesCache.push(l),l},e.prototype.updateRawTexture3D=function(e,i,s,n,a=null,r=f.TEXTURETYPE_UNSIGNED_BYTE){if(this._doNotHandleContextLost||(e._bufferView=i,e.format=s,e.invertY=n,e._compression=a),i){const a=e._hardwareTexture;s===f.TEXTUREFORMAT_RGB&&(i=t(i,e.width,e.height,r));const o=new Uint8Array(i.buffer,i.byteOffset,i.byteLength);this._textureHelper.updateTexture(o,e,e.width,e.height,e.depth,a.format,0,0,n,!1,0,0),e.generateMipMaps&&this._generateMipmaps(e,this._uploadEncoder)}e.isReady=!0},e.prototype.createRawTexture2DArray=function(e,t,i,s,n,a,r,o,u=null,h=f.TEXTURETYPE_UNSIGNED_BYTE,d=0,l){const p=new g(this,11);return p.baseWidth=t,p.baseHeight=i,p.baseDepth=s,p.width=t,p.height=i,p.depth=s,p.format=n,p.type=h,p.generateMipMaps=a,p.samplingMode=o,p.is2DArray=!0,p._creationFlags=d,this._doNotHandleContextLost||(p._bufferView=e),this._textureHelper.updateMipLevelCountForInternalTexture(p,l),this._textureHelper.createGPUTextureForInternalTexture(p,t,i,s,d),this.updateRawTexture2DArray(p,e,n,r,u,h),this._internalTexturesCache.push(p),p},e.prototype.updateRawTexture2DArray=function(e,i,s,n,a=null,r=f.TEXTURETYPE_UNSIGNED_BYTE,o){if(this._doNotHandleContextLost||(e._bufferView=i,e.format=s,e.invertY=n,e._compression=a,void 0!==o&&i&&(e._bufferViewArray||(e._bufferViewArray=new Array(e.mipLevelCount)),e._bufferViewArray[o]=i)),i){const a=e._hardwareTexture;s===f.TEXTUREFORMAT_RGB&&(i=t(i,e.width,e.height,r));const u=new Uint8Array(i.buffer,i.byteOffset,i.byteLength),h=Math.max(1,e.width>>(o??0)),d=Math.max(1,e.height>>(o??0));this._textureHelper.updateTexture(u,e,h,d,e.depth,a.format,0,o??0,n,!1,0,0),e.generateMipMaps&&!o&&this._generateMipmaps(e,this._uploadEncoder)}e.isReady=!0})}();let q=!1;q||(q=!0,e.prototype._readTexturePixels=function(e,t,i,s=-1,n=0,a=null,r=!0,o=!1,u=0,h=0){const d=e._hardwareTexture;return r&&this.flushFramebuffer(),this._textureHelper.readPixels(d.underlyingResource,u,h,t,i,d.format,s,n,a,o)},e.prototype._readTexturePixelsSync=function(){throw"_readTexturePixelsSync is unsupported in WebGPU!"});let $=!1;$||($=!0,e.prototype._createDepthStencilCubeTexture=function(e,t){const s=new g(this,t.generateStencil?12:14);s.isCube=!0,s.label=t.label;const n={bilinearFiltering:!1,comparisonFunction:0,samples:1,depthTextureFormat:t.generateStencil?f.TEXTUREFORMAT_DEPTH24_STENCIL8:f.TEXTUREFORMAT_DEPTH32_FLOAT,...t};s.format=n.depthTextureFormat,this._setupDepthStencilTexture(s,e,n.bilinearFiltering,n.comparisonFunction,n.samples),this._textureHelper.createGPUTextureForInternalTexture(s);const a=s._hardwareTexture;return s.type=i.GetTextureTypeFromFormat(a.format),this._internalTexturesCache.push(s),s},e.prototype.createCubeTexture=function(e,t,i,s,n=null,a=null,r,o=null,u=!1,h=0,d=0,l=null,p,_=!1,c=null){return this.createCubeTextureBase(e,t,i,!!s,n,a,r,o,u,h,d,l,null,(e,t)=>{const i=t,a=i[0].width,o=a;this._setCubeMapTextureParams(e,!s),e.format=r??-1;const u=this._textureHelper.createGPUTextureForInternalTexture(e,a,o);this._textureHelper.updateCubeTextures(i,e,a,o,u.format,!1,!1,0,0),s||this._generateMipmaps(e,this._uploadEncoder),e.isReady=!0,e.onLoadedObservable.notifyObservers(e),e.onLoadedObservable.clear(),n&&n()},!!_,c)},e.prototype._setCubeMapTextureParams=function(e,t,i){e.samplingMode=t?f.TEXTURE_TRILINEAR_SAMPLINGMODE:f.TEXTURE_BILINEAR_SAMPLINGMODE,e._cachedWrapU=f.TEXTURE_CLAMP_ADDRESSMODE,e._cachedWrapV=f.TEXTURE_CLAMP_ADDRESSMODE,i&&(e._maxLodLevel=i)},e.prototype.generateMipMapsForCubemap=function(e){if(e.generateMipMaps){const t=e._hardwareTexture?.underlyingResource;t||this._textureHelper.createGPUTextureForInternalTexture(e),this._generateMipmaps(e)}});class J extends y{constructor(e,t,i,n,a){super(e,t,i,n,a),this._disableEngineYFlip=!1,n.enableGPUTimingMeasurements&&(this.gpuTimeInFrame=new s)}}let K=!1;K||(K=!0,e.prototype._createHardwareRenderTargetWrapper=function(e,t,i){const s=new J(e,t,i,this);return this._renderTargetWrapperCache.push(s),s},e.prototype.createRenderTargetTexture=function(e,t){const i=this._createHardwareRenderTargetWrapper(!1,!1,e),s={};void 0!==t&&"object"==typeof t?(s.generateMipMaps=t.generateMipMaps,s.generateDepthBuffer=void 0===t.generateDepthBuffer||t.generateDepthBuffer,s.generateStencilBuffer=s.generateDepthBuffer&&t.generateStencilBuffer,s.samplingMode=void 0===t.samplingMode?f.TEXTURE_TRILINEAR_SAMPLINGMODE:t.samplingMode,s.creationFlags=t.creationFlags??0,s.noColorAttachment=!!t.noColorAttachment,s.colorAttachment=t.colorAttachment,s.samples=t.samples,s.label=t.label,s.format=t.format,s.type=t.type):(s.generateMipMaps=t,s.generateDepthBuffer=!0,s.generateStencilBuffer=!1,s.samplingMode=f.TEXTURE_TRILINEAR_SAMPLINGMODE,s.creationFlags=0,s.noColorAttachment=!1);const n=s.colorAttachment||(s.noColorAttachment?null:this._createInternalTexture(e,s,!0,5));return i.label=s.label??"RenderTargetWrapper",i._samples=s.colorAttachment?.samples??s.samples??1,i._generateDepthBuffer=s.generateDepthBuffer,i._generateStencilBuffer=!!s.generateStencilBuffer,i.setTextures(n),(i._generateDepthBuffer||i._generateStencilBuffer)&&i.createDepthStencilTexture(0,!1,i._generateStencilBuffer,i.samples,s.generateStencilBuffer?f.TEXTUREFORMAT_DEPTH24_STENCIL8:f.TEXTUREFORMAT_DEPTH32_FLOAT,s.label?s.label+"-DepthStencil":void 0),n&&!s.colorAttachment&&(void 0!==t&&"object"==typeof t&&t.createMipMaps&&!s.generateMipMaps&&(n.generateMipMaps=!0),this._textureHelper.createGPUTextureForInternalTexture(n,void 0,void 0,void 0,s.creationFlags),void 0!==t&&"object"==typeof t&&t.createMipMaps&&!s.generateMipMaps&&(n.generateMipMaps=!1)),i},e.prototype._createDepthStencilTexture=function(e,t,i){const s={bilinearFiltering:!1,comparisonFunction:0,samples:1,depthTextureFormat:t.generateStencil?f.TEXTUREFORMAT_DEPTH24_STENCIL8:f.TEXTUREFORMAT_DEPTH32_FLOAT,...t},n=A(s.depthTextureFormat);i._depthStencilTextureWithStencil=n;const a=new g(this,n?12:14);return a.label=t.label,a.format=s.depthTextureFormat,a.type=b(a.format),this._setupDepthStencilTexture(a,e,s.bilinearFiltering,s.comparisonFunction,s.samples),this._textureHelper.createGPUTextureForInternalTexture(a),this._internalTexturesCache.push(a),a},e.prototype._setupDepthStencilTexture=function(e,t,i,s,n=1){const a=t.width??t,r=t.height??t,o=t.layers||0,u=t.depth||0;e.baseWidth=a,e.baseHeight=r,e.width=a,e.height=r,e.is2DArray=o>0,e.is3D=u>0,e.depth=o||u,e.isReady=!0,e.samples=n,e.generateMipMaps=!1,e.samplingMode=i?f.TEXTURE_BILINEAR_SAMPLINGMODE:f.TEXTURE_NEAREST_SAMPLINGMODE,e.type=f.TEXTURETYPE_FLOAT,e._comparisonFunction=s,e._cachedWrapU=f.TEXTURE_CLAMP_ADDRESSMODE,e._cachedWrapV=f.TEXTURE_CLAMP_ADDRESSMODE},e.prototype.updateRenderTargetTextureSampleCount=function(e,t){if(!e||!e.texture||e.samples===t)return t;t=Math.min(t,this.getCaps().maxMSAASamples);const i=e.texture._hardwareTexture;return i?.releaseMSAATextures(),e._depthStencilTexture&&(e._depthStencilTexture._hardwareTexture?.releaseMSAATextures(),e._depthStencilTexture.samples=t),e._samples=t,e.texture.samples=t,t});let ee=!1;ee||(ee=!0,e.prototype.setDepthStencilTexture=function(e,t,i,s){i&&i.depthStencilTexture?this._setTexture(e,i,!1,!0,s):this._setTexture(e,null,void 0,void 0,s)});let te=!1;te||(te=!0,e.prototype.createRenderTargetCubeTexture=function(e,t){const i=this._createHardwareRenderTargetWrapper(!1,!0,e),s={generateMipMaps:!0,generateDepthBuffer:!0,generateStencilBuffer:!1,type:f.TEXTURETYPE_UNSIGNED_BYTE,samplingMode:f.TEXTURE_TRILINEAR_SAMPLINGMODE,format:f.TEXTUREFORMAT_RGBA,samples:1,...t};s.generateStencilBuffer=s.generateDepthBuffer&&s.generateStencilBuffer,i.label=s.label??"RenderTargetWrapper",i._generateDepthBuffer=s.generateDepthBuffer,i._generateStencilBuffer=s.generateStencilBuffer;const n=new g(this,5);return n.width=e,n.height=e,n.depth=0,n.isReady=!0,n.isCube=!0,n.samples=s.samples,n.generateMipMaps=s.generateMipMaps,n.samplingMode=s.samplingMode,n.type=s.type,n.format=s.format,this._internalTexturesCache.push(n),i.setTextures(n),(i._generateDepthBuffer||i._generateStencilBuffer)&&i.createDepthStencilTexture(0,void 0===s.samplingMode||s.samplingMode===f.TEXTURE_BILINEAR_SAMPLINGMODE||s.samplingMode===f.TEXTURE_LINEAR_LINEAR||s.samplingMode===f.TEXTURE_TRILINEAR_SAMPLINGMODE||s.samplingMode===f.TEXTURE_LINEAR_LINEAR_MIPLINEAR||s.samplingMode===f.TEXTURE_NEAREST_LINEAR_MIPNEAREST||s.samplingMode===f.TEXTURE_NEAREST_LINEAR_MIPLINEAR||s.samplingMode===f.TEXTURE_NEAREST_LINEAR||s.samplingMode===f.TEXTURE_LINEAR_LINEAR_MIPNEAREST,i._generateStencilBuffer,i.samples),t&&t.createMipMaps&&!s.generateMipMaps&&(n.generateMipMaps=!0),this._textureHelper.createGPUTextureForInternalTexture(n),t&&t.createMipMaps&&!s.generateMipMaps&&(n.generateMipMaps=!1),i});let ie=!1;ie||(ie=!0,e.prototype.getGPUFrameTimeCounter=function(){return this._timestampQuery.gpuFrameTimeCounter},e.prototype.captureGPUFrameTime=function(e){this._timestampQuery.enable=e&&!!this._caps.timerQuery},e.prototype.createQuery=function(){return this._occlusionQuery.createQuery()},e.prototype.deleteQuery=function(e){return this._occlusionQuery.deleteQuery(e),this},e.prototype.isQueryResultAvailable=function(e){return this._occlusionQuery.isQueryResultAvailable(e)},e.prototype.getQueryResult=function(e){return this._occlusionQuery.getQueryResult(e)},e.prototype.beginOcclusionQuery=function(e,t){return this.compatibilityMode?!!this._occlusionQuery.canBeginQuery(t)&&(this._currentRenderPass?.beginOcclusionQuery(t),!0):(this._bundleList.addItem(new n(t)),!0)},e.prototype.endOcclusionQuery=function(){return this.compatibilityMode?this._currentRenderPass?.endOcclusionQuery():this._bundleList.addItem(new a),this});export{r as WebGPUEngine};
//# sourceMappingURL=webgpuEngine-B_WEA2Tm.esm.min.js.map