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.

86 lines (82 loc) 3.77 kB
import { d as RichTypeNumber } from './declarationMapper-CqO08-WM.esm.js'; import { c as FlowGraphExecutionBlockWithOutSignal } from './KHR_interactivity-CEwUaqxQ.esm.js'; import { u as RegisterClass } from './index-MZPybX0H.esm.js'; import './objectModelMapping-De5EKNEZ.esm.js'; import './spotLight.pure-CRdZC6Ci.esm.js'; /** This file must only contain pure code and pure imports */ /** * A block that throttles the execution of its output flow. */ class FlowGraphThrottleBlock extends FlowGraphExecutionBlockWithOutSignal { constructor(config) { super(config); this.reset = this._registerSignalInput("reset"); this.duration = this.registerDataInput("duration", RichTypeNumber); this.lastRemainingTime = this.registerDataOutput("lastRemainingTime", RichTypeNumber, NaN); } _execute(context, callingSignal) { if (callingSignal === this.reset) { this.lastRemainingTime.setValue(NaN, context); context._setExecutionVariable(this, "lastRemainingTime", NaN); context._setExecutionVariable(this, "timestamp", 0); return; } // in seconds const durationValue = this.duration.getValue(context); if (durationValue <= 0 || isNaN(durationValue) || !isFinite(durationValue)) { return this._reportError(context, "Invalid duration in Throttle block"); } const lastRemainingTime = context._getExecutionVariable(this, "lastRemainingTime", NaN); // Using Date.now() to get ms since epoch. not using performance.now() because its precision is not needed here const currentTime = Date.now(); if (isNaN(lastRemainingTime)) { this.lastRemainingTime.setValue(0, context); context._setExecutionVariable(this, "lastRemainingTime", 0); context._setExecutionVariable(this, "timestamp", currentTime); // according to glTF interactivity specs return this.out._activateSignal(context); } else { const elapsedTime = currentTime - context._getExecutionVariable(this, "timestamp", 0); // duration is in seconds, so we need to multiply by 1000 const durationInMs = durationValue * 1000; if (durationInMs <= elapsedTime) { this.lastRemainingTime.setValue(0, context); context._setExecutionVariable(this, "lastRemainingTime", 0); context._setExecutionVariable(this, "timestamp", currentTime); return this.out._activateSignal(context); } else { const remainingTime = durationInMs - elapsedTime; // output is in seconds this.lastRemainingTime.setValue(remainingTime / 1000, context); context._setExecutionVariable(this, "lastRemainingTime", remainingTime); } } } /** * @returns class name of the block. */ getClassName() { return "FlowGraphThrottleBlock" /* FlowGraphBlockNames.Throttle */; } } let _Registered = false; /** * Register side effects for flowGraphThrottleBlock. * Safe to call multiple times; only the first call has an effect. */ function RegisterFlowGraphThrottleBlock() { if (_Registered) { return; } _Registered = true; RegisterClass("FlowGraphThrottleBlock" /* FlowGraphBlockNames.Throttle */, FlowGraphThrottleBlock); } /** * Re-exports pure implementation and applies runtime side effects. * Import flowGraphThrottleBlock.pure for tree-shakeable, side-effect-free usage. */ RegisterFlowGraphThrottleBlock(); export { FlowGraphThrottleBlock, RegisterFlowGraphThrottleBlock }; //# sourceMappingURL=flowGraphThrottleBlock-BqC1Nbi0.esm.js.map