UNPKG

@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) 5.87 kB
import{O as e,V as t,aD as s,bI as i,y as n,bR as a}from"./index-BPURObVq.esm.min.js";var o;!function(e){e[e.HAS_INPUTS=1]="HAS_INPUTS",e[e.HAS_OUTPUTS=2]="HAS_OUTPUTS",e[e.HAS_INPUTS_AND_OUTPUTS=3]="HAS_INPUTS_AND_OUTPUTS"}(o||(o={}));class r{constructor(t,s){this.onDisposeObservable=new e,this.engine=t,1&s&&(this._upstreamNodes=new Set),2&s&&(this._downstreamNodes=new Set)}dispose(){if(this._downstreamNodes){for(const e of Array.from(this._downstreamNodes))if(!this._disconnect(e))throw new Error("Disconnect failed");this._downstreamNodes.clear()}if(this._upstreamNodes){for(const e of Array.from(this._upstreamNodes))if(!e._disconnect(this))throw new Error("Disconnect failed");this._upstreamNodes.clear()}this.onDisposeObservable.notifyObservers(this),this.onDisposeObservable.clear()}_connect(e){return!!this._downstreamNodes&&(!this._downstreamNodes.has(e)&&(!!e._onConnect(this)&&(this._downstreamNodes.add(e),!0)))}_disconnect(e){return!!this._downstreamNodes&&(!!this._downstreamNodes.delete(e)&&e._onDisconnect(this))}_onConnect(e){return!!this._upstreamNodes&&(!this._upstreamNodes.has(e)&&(this._upstreamNodes.add(e),!0))}_onDisconnect(e){return this._upstreamNodes?.delete(e)??!1}}class h extends r{constructor(t,s,i){super(s,i),this.onNameChangedObservable=new e,this._name=t}get name(){return this._name}set name(e){if(this._name===e)return;const t=this._name;this._name=e,this.onNameChangedObservable.notifyObservers({newName:e,oldName:t,node:this})}dispose(){super.dispose(),this.onNameChangedObservable.clear()}}class d{constructor(e){this._attachmentType=3,this._position=new t,this._rotationQuaternion=new s,this._sceneNode=null,this._useBoundingBox=!1,this.dispose=()=>{this.detach()},this._spatialAudioNode=e}get isAttached(){return null!==this._sceneNode}get sceneNode(){return this._sceneNode}get useBoundingBox(){return this._useBoundingBox}get attachmentType(){return this._attachmentType}attach(e,t,s){this._sceneNode!==e&&(this.detach(),e&&(this._attachmentType=s,this._sceneNode=e,this._sceneNode.onDisposeObservable.add(this.dispose),this._useBoundingBox=t))}detach(){this._sceneNode?.onDisposeObservable.removeCallback(this.dispose),this._sceneNode=null}update(){const e=!!(1&this._attachmentType);e&&(this._useBoundingBox&&this._sceneNode.getBoundingInfo?this._position.copyFrom(this._sceneNode.getBoundingInfo().boundingBox.centerWorld):this._sceneNode?.getWorldMatrix().getTranslationToRef(this._position),this._spatialAudioNode.position.copyFrom(this._position),this._spatialAudioNode._updatePosition()),2&this._attachmentType&&(this._sceneNode?.getWorldMatrix().decompose(void 0,this._rotationQuaternion),this._spatialAudioNode.rotationQuaternion.copyFrom(this._rotationQuaternion),this._spatialAudioNode._updateRotation()),e||!("panningEnabled"in this._spatialAudioNode)||this._spatialAudioNode.panningEnabled||this._spatialAudioNode._updatePosition()}}const u=new RegExp("\\.(\\w{3,4})($|\\?)"),l=100,_=new Float32Array([0,0]);let m=null,c=null,p=null;function g(e,t,s){let i;if(m||(m=new Float32Array(l)),"linear"===e)return _[0]=t,_[1]=s,_;if("exponential"===e)i=function(){if(!c){c=new Float32Array(l);const e=1/99;let t=e;for(let s=1;s<l;s++)c[s]=Math.exp(-11.512925464970227*(1-t)),t+=e}return c}();else{if("logarithmic"!==e)throw new Error(`Unknown ramp shape: ${e}`);i=function(){if(!p){p=new Float32Array(l);const e=.01;let t=e;for(let s=0;s<l;s++)p[s]=1+Math.log10(t)/Math.log10(l),t+=e}return p}()}const n=Math.sign(s-t),a=Math.abs(s-t);if(1===n)for(let e=0;e<i.length;e++)m[e]=t+a*i[e];else{let e=99;for(let s=0;s<i.length;s++,e--)m[s]=t-a*(1-i[e])}return m}function f(e){return e.replace(/#/gm,"%23")}function N(e){const{url:t,headers:s}=i._CollectCustomizations(e);return Object.keys(s).length>0&&n.Warn("WebAudioStreamingSound: Custom request headers cannot be applied to a streaming <audio> element and will be ignored. To use custom headers with audio, switch to a static (non-streaming) sound which fetches the file up-front."),t}async function T(e){const t=await i.FetchAsync(e);if(!t.ok)throw new Error(`HTTP ${t.status} loading '${e}': ${t.statusText}`);return{data:await t.arrayBuffer(),contentType:t.headers.get("Content-Type")??""}}let w=!0;class b{constructor(e,t){this._rampEndTime=0,this._engine=e,this._param=t,this._targetValue=t.value}get isRamping(){return this._engine.currentTime<this._rampEndTime}get targetValue(){return this._targetValue}set targetValue(e){this.setTargetValue(e)}get value(){return this._param.value}dispose(){this._param=null,this._engine=null}setTargetValue(e,t=null){if(!Number.isFinite(e))return void n.Warn(`Attempted to set audio parameter to non-finite value: ${e}`);this._param.cancelScheduledValues(0);const s="string"==typeof t?.shape?t.shape:"linear",i=this._engine.currentTime;if("none"===s)return this._param.value=this._targetValue=e,void(this._rampEndTime=i);let a="number"==typeof t?.duration?Math.max(t.duration,this._engine.parameterRampDuration):this._engine.parameterRampDuration;if(this._targetValue=e,(a=Math.max(this._engine.parameterRampDuration,a))<1e-6)this._param.setValueAtTime(e,i);else try{this._param.setValueCurveAtTime(g(s,Number.isFinite(this._param.value)?this._param.value:0,e),i,a),this._rampEndTime=i+a}catch(e){w&&(n.Warn(`Audio parameter ramping failed: ${e.message}`),w=!1)}}}class A{constructor(e,t,s){if(this._autoUpdate=!0,this._lastUpdateTime=0,this.minUpdateTime=0,!t)return;this.minUpdateTime=s;const i=()=>{if(!this._autoUpdate)return;let t=!1;if(0<this.minUpdateTime){const e=a.Now;this._lastUpdateTime&&e-this._lastUpdateTime<1e3*this.minUpdateTime&&(t=!0),this._lastUpdateTime=e}t||e.update(),requestAnimationFrame(i)};requestAnimationFrame(i)}dispose(){this._autoUpdate=!1}}export{r as A,N as _,f as a,T as b,u as c,b as d,d as e,A as f,h as g}; //# sourceMappingURL=spatialWebAudioUpdaterComponent-LOlF6N8J.esm.min.js.map