@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.
89 lines (85 loc) • 3.38 kB
JavaScript
import { a as FlowGraphEventBlock } from './KHR_interactivity-CEwUaqxQ.esm.js';
import { R as RichTypeAny } from './declarationMapper-CqO08-WM.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 */
/**
* @experimental
* An event block that fires when an Audio V2 sound stops or ends.
* Subscribes to the sound's onEndedObservable, which fires when playback
* stops for any reason (natural completion or a manual call to stop()).
* Does not fire when a looping sound naturally restarts, but will still
* fire if a looping sound is explicitly stopped.
*/
class FlowGraphSoundEndedEventBlock extends FlowGraphEventBlock {
/**
* Constructs a new FlowGraphSoundEndedEventBlock.
* @param config - optional configuration for the block
*/
constructor(config) {
super(config);
this.sound = this.registerDataInput("sound", RichTypeAny);
}
/**
* @internal
*/
_preparePendingTasks(context) {
const soundValue = this.sound.getValue(context);
if (!soundValue) {
this._reportError(context, "No sound provided for sound-ended event");
return;
}
const observer = soundValue.onEndedObservable.add(() => {
this._execute(context);
});
// Store observer and subscribed sound per-context for safe multi-context usage
context._setExecutionVariable(this, "_soundEndedObserver", observer);
context._setExecutionVariable(this, "_subscribedSound", soundValue);
}
/**
* @internal
*/
_executeEvent(_context, _payload) {
// This block manages its own observable subscription, so the
// central event coordinator does not dispatch to it.
return true;
}
/**
* @internal
*/
_cancelPendingTasks(context) {
const observer = context._getExecutionVariable(this, "_soundEndedObserver", null);
const subscribedSound = context._getExecutionVariable(this, "_subscribedSound", null);
if (observer && subscribedSound) {
subscribedSound.onEndedObservable.remove(observer);
}
context._setExecutionVariable(this, "_soundEndedObserver", null);
context._setExecutionVariable(this, "_subscribedSound", null);
}
/**
* @returns class name of the block.
*/
getClassName() {
return "FlowGraphSoundEndedEventBlock" /* FlowGraphBlockNames.AudioSoundEndedEvent */;
}
}
let _Registered = false;
/**
* Register side effects for flowGraphSoundEndedEventBlock.
* Safe to call multiple times; only the first call has an effect.
*/
function RegisterFlowGraphSoundEndedEventBlock() {
if (_Registered) {
return;
}
_Registered = true;
RegisterClass("FlowGraphSoundEndedEventBlock" /* FlowGraphBlockNames.AudioSoundEndedEvent */, FlowGraphSoundEndedEventBlock);
}
/**
* Re-exports pure implementation and applies runtime side effects.
* Import flowGraphSoundEndedEventBlock.pure for tree-shakeable, side-effect-free usage.
*/
RegisterFlowGraphSoundEndedEventBlock();
export { FlowGraphSoundEndedEventBlock, RegisterFlowGraphSoundEndedEventBlock };
//# sourceMappingURL=flowGraphSoundEndedEventBlock-cwHSLLsz.esm.js.map