@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) • 4.33 kB
JavaScript
import{a as e}from"./KHR_interactivity-CKt1TdMW.esm.min.js";import{f as t,k as s,b as i}from"./declarationMapper-13w1YGqM.esm.min.js";import{O as a,L as n,R as r}from"./index-Bw2N6w1y.esm.min.js";import"./objectModelMapping-DX92iJ8M.esm.min.js";var o;!function(e){e[e.INIT=0]="INIT",e[e.STARTED=1]="STARTED",e[e.ENDED=2]="ENDED"}(o||(o={}));class l{constructor(e){this.onEachCountObservable=new a,this.onTimerAbortedObservable=new a,this.onTimerEndedObservable=new a,this.onStateChangedObservable=new a,this._observer=null,this._breakOnNextTick=!1,this._tick=e=>{const t=Date.now();this._timer=t-this._startTime;const s={startTime:this._startTime,currentTime:t,deltaTime:this._timer,completeRate:this._timer/this._timeToEnd,payload:e},i=this._breakOnNextTick||this._breakCondition(s);i||this._timer>=this._timeToEnd?this._stop(s,i):this.onEachCountObservable.notifyObservers(s)},this._setState(0),this._contextObservable=e.contextObservable,this._observableParameters=e.observableParameters??{},this._breakCondition=e.breakCondition??(()=>!1),this._timeToEnd=e.timeout,e.onEnded&&this.onTimerEndedObservable.add(e.onEnded),e.onTick&&this.onEachCountObservable.add(e.onTick),e.onAborted&&this.onTimerAbortedObservable.add(e.onAborted)}set breakCondition(e){this._breakCondition=e}clearObservables(){this.onEachCountObservable.clear(),this.onTimerAbortedObservable.clear(),this.onTimerEndedObservable.clear(),this.onStateChangedObservable.clear()}start(e=this._timeToEnd){if(1===this._state)throw new Error("Timer already started. Please stop it before starting again");this._timeToEnd=e,this._startTime=Date.now(),this._timer=0,this._observer=this._contextObservable.add(this._tick,this._observableParameters.mask,this._observableParameters.insertFirst,this._observableParameters.scope),this._setState(1)}stop(){1===this._state&&(this._breakOnNextTick=!0)}dispose(){this._observer&&this._contextObservable.remove(this._observer),this.clearObservables()}_setState(e){this._state=e,this.onStateChangedObservable.notifyObservers(this._state)}_stop(e,t=!1){this._contextObservable.remove(this._observer),this._setState(2),t?this.onTimerAbortedObservable.notifyObservers(e):this.onTimerEndedObservable.notifyObservers(e)}}class b extends e{constructor(e){super(e),this.cancel=this._registerSignalInput("cancel"),this.duration=this.registerDataInput("duration",t),this.lastDelayIndex=this.registerDataOutput("lastDelayIndex",s,new i(-1))}_preparePendingTasks(e){const t=this.duration.getValue(e);if(t<0||isNaN(t)||!isFinite(t))return this._reportError(e,"Invalid duration in SetDelay block");if(e._getGlobalContextVariable("activeDelays",0)>=b.MaxParallelDelayCount)return this._reportError(e,"Max parallel delays reached");const s=e._getGlobalContextVariable("lastDelayIndex",-1),a=e._getExecutionVariable(this,"pendingDelays",[]),n=e.configuration.scene,r=new l({timeout:1e3*t,contextObservable:n.onBeforeRenderObservable,onEnded:()=>this._onEnded(r,e)});r.start();const o=s+1;this.lastDelayIndex.setValue(new i(o),e),e._setGlobalContextVariable("lastDelayIndex",o),a[o]=r,e._setExecutionVariable(this,"pendingDelays",a),this._updateGlobalTimers(e)}_cancelPendingTasks(e){const t=e._getExecutionVariable(this,"pendingDelays",[]);for(const e of t)e?.dispose();e._deleteExecutionVariable(this,"pendingDelays"),this.lastDelayIndex.setValue(new i(-1),e),this._updateGlobalTimers(e)}_execute(e,t){t!==this.cancel?(this._preparePendingTasks(e),this.out._activateSignal(e)):this._cancelPendingTasks(e)}getClassName(){return"FlowGraphSetDelayBlock"}_onEnded(e,t){const s=t._getExecutionVariable(this,"pendingDelays",[]),i=s.indexOf(e);-1!==i?s.splice(i,1):n.Warn("FlowGraphTimerBlock: Timer ended but was not found in the running timers list"),t._removePendingBlock(this),this.done._activateSignal(t),this._updateGlobalTimers(t)}_updateGlobalTimers(e){const t=e._getExecutionVariable(this,"pendingDelays",[]),s=e._getGlobalContextVariable("pendingDelays",[]);for(let e=0;e<t.length;e++){if(!t[e])continue;const i=t[e];s[e]&&s[e]!==i?n.Warn("FlowGraphTimerBlock: Timer ended but was not found in the running timers list"):s[e]=i}e._setGlobalContextVariable("pendingDelays",s)}}b.MaxParallelDelayCount=100,r("FlowGraphSetDelayBlock",b);export{b as FlowGraphSetDelayBlock};
//# sourceMappingURL=flowGraphSetDelayBlock-BI9Z9bYV.esm.min.js.map