|
@@ -1,27 +1,26 @@
|
|
/// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
|
|
/// <reference path="../../../../../dist/preview release/babylon.d.ts"/>
|
|
|
|
|
|
module BABYLON.GLTF2.Extensions {
|
|
module BABYLON.GLTF2.Extensions {
|
|
-
|
|
|
|
const NAME = "MSFT_audio_emitter";
|
|
const NAME = "MSFT_audio_emitter";
|
|
|
|
|
|
- interface _IClipReference {
|
|
|
|
|
|
+ interface IClipReference {
|
|
clip: number;
|
|
clip: number;
|
|
weight?: number;
|
|
weight?: number;
|
|
}
|
|
}
|
|
|
|
|
|
- interface _IEmittersReference {
|
|
|
|
|
|
+ interface IEmittersReference {
|
|
emitters: number[];
|
|
emitters: number[];
|
|
}
|
|
}
|
|
|
|
|
|
- const enum _DistanceModel {
|
|
|
|
|
|
+ const enum DistanceModel {
|
|
linear = "linear",
|
|
linear = "linear",
|
|
inverse = "inverse",
|
|
inverse = "inverse",
|
|
exponential = "exponential",
|
|
exponential = "exponential",
|
|
}
|
|
}
|
|
|
|
|
|
- interface _IEmitter {
|
|
|
|
|
|
+ interface IEmitter {
|
|
name?: string;
|
|
name?: string;
|
|
- distanceModel?: _DistanceModel;
|
|
|
|
|
|
+ distanceModel?: DistanceModel;
|
|
refDistance?: number;
|
|
refDistance?: number;
|
|
maxDistance?: number;
|
|
maxDistance?: number;
|
|
rolloffFactor?: number;
|
|
rolloffFactor?: number;
|
|
@@ -29,74 +28,178 @@ module BABYLON.GLTF2.Extensions {
|
|
outerAngle?: number;
|
|
outerAngle?: number;
|
|
loop?: boolean;
|
|
loop?: boolean;
|
|
volume?: number;
|
|
volume?: number;
|
|
- clips: _IClipReference[];
|
|
|
|
|
|
+ clips: IClipReference[];
|
|
}
|
|
}
|
|
|
|
|
|
- const enum _AudioMimeType {
|
|
|
|
|
|
+ const enum AudioMimeType {
|
|
WAV = "audio/wav",
|
|
WAV = "audio/wav",
|
|
}
|
|
}
|
|
|
|
|
|
- interface _IClip {
|
|
|
|
|
|
+ interface IClip {
|
|
uri?: string;
|
|
uri?: string;
|
|
bufferView?: number;
|
|
bufferView?: number;
|
|
- mimeType?: _AudioMimeType;
|
|
|
|
|
|
+ mimeType?: AudioMimeType;
|
|
}
|
|
}
|
|
|
|
|
|
- interface _ILoaderClip extends _IClip, _IArrayItem {
|
|
|
|
|
|
+ interface ILoaderClip extends IClip, IArrayItem {
|
|
_objectURL?: Promise<string>;
|
|
_objectURL?: Promise<string>;
|
|
}
|
|
}
|
|
|
|
|
|
- interface _ILoaderEmitter extends _IEmitter, _IArrayItem {
|
|
|
|
- _babylonData?: {
|
|
|
|
|
|
+ interface ILoaderEmitter extends IEmitter, IArrayItem {
|
|
|
|
+ _babylonData?: {
|
|
sound?: WeightedSound;
|
|
sound?: WeightedSound;
|
|
loaded: Promise<void>;
|
|
loaded: Promise<void>;
|
|
};
|
|
};
|
|
_babylonSounds: Sound[];
|
|
_babylonSounds: Sound[];
|
|
}
|
|
}
|
|
|
|
|
|
- interface _IMSFTAudioEmitter {
|
|
|
|
- clips: _ILoaderClip[];
|
|
|
|
- emitters: _ILoaderEmitter[];
|
|
|
|
|
|
+ interface IMSFTAudioEmitter {
|
|
|
|
+ clips: ILoaderClip[];
|
|
|
|
+ emitters: ILoaderEmitter[];
|
|
}
|
|
}
|
|
|
|
|
|
- const enum _AnimationEventAction {
|
|
|
|
|
|
+ const enum AnimationEventAction {
|
|
play = "play",
|
|
play = "play",
|
|
pause = "pause",
|
|
pause = "pause",
|
|
stop = "stop",
|
|
stop = "stop",
|
|
}
|
|
}
|
|
|
|
|
|
- interface _IAnimationEvent {
|
|
|
|
- action: _AnimationEventAction,
|
|
|
|
|
|
+ interface IAnimationEvent {
|
|
|
|
+ action: AnimationEventAction,
|
|
emitter: number;
|
|
emitter: number;
|
|
time: number;
|
|
time: number;
|
|
startOffset?: number;
|
|
startOffset?: number;
|
|
}
|
|
}
|
|
|
|
|
|
- interface _ILoaderAnimationEvent extends _IAnimationEvent, _IArrayItem {
|
|
|
|
|
|
+ interface ILoaderAnimationEvent extends IAnimationEvent, IArrayItem {
|
|
}
|
|
}
|
|
|
|
|
|
- interface _ILoaderAnimationEvents {
|
|
|
|
- events: _ILoaderAnimationEvent[];
|
|
|
|
|
|
+ interface ILoaderAnimationEvents {
|
|
|
|
+ events: ILoaderAnimationEvent[];
|
|
}
|
|
}
|
|
|
|
|
|
/**
|
|
/**
|
|
* [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
|
|
* [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
|
|
*/
|
|
*/
|
|
- export class MSFT_audio_emitter extends GLTFLoaderExtension {
|
|
|
|
|
|
+ export class MSFT_audio_emitter implements IGLTFLoaderExtension {
|
|
|
|
+ /** The name of this extension. */
|
|
public readonly name = NAME;
|
|
public readonly name = NAME;
|
|
|
|
|
|
- private _loadClipAsync(context: string, clip: _ILoaderClip): Promise<string> {
|
|
|
|
|
|
+ /** Defines whether this extension is enabled. */
|
|
|
|
+ public enabled = true;
|
|
|
|
+
|
|
|
|
+ private _loader: GLTFLoader;
|
|
|
|
+ private _clips: Array<ILoaderClip>;
|
|
|
|
+ private _emitters: Array<ILoaderEmitter>;
|
|
|
|
+
|
|
|
|
+ /** @hidden */
|
|
|
|
+ constructor(loader: GLTFLoader) {
|
|
|
|
+ this._loader = loader;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public dispose() {
|
|
|
|
+ delete this._loader;
|
|
|
|
+ delete this._clips;
|
|
|
|
+ delete this._emitters;
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public onLoading(): void {
|
|
|
|
+ const extensions = this._loader.gltf.extensions;
|
|
|
|
+ if (extensions && extensions[this.name]) {
|
|
|
|
+ const extension = extensions[this.name] as IMSFTAudioEmitter;
|
|
|
|
+
|
|
|
|
+ this._clips = extension.clips;
|
|
|
|
+ this._emitters = extension.emitters;
|
|
|
|
+
|
|
|
|
+ ArrayItem.Assign(this._clips);
|
|
|
|
+ ArrayItem.Assign(this._emitters);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public loadSceneAsync(context: string, scene: ILoaderScene): Nullable<Promise<void>> {
|
|
|
|
+ return GLTFLoader.LoadExtensionAsync<IEmittersReference>(context, scene, this.name, (extensionContext, extension) => {
|
|
|
|
+ const promises = new Array<Promise<any>>();
|
|
|
|
+
|
|
|
|
+ promises.push(this._loader.loadSceneAsync(context, scene));
|
|
|
|
+
|
|
|
|
+ for (const emitterIndex of extension.emitters) {
|
|
|
|
+ const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);
|
|
|
|
+ if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
|
|
|
|
+ emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
|
|
|
|
+ throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Promise.all(promises).then(() => {});
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public loadNodeAsync(context: string, node: ILoaderNode, assign: (babylonMesh: Mesh) => void): Nullable<Promise<Mesh>> {
|
|
|
|
+ return GLTFLoader.LoadExtensionAsync<IEmittersReference, Mesh>(context, node, this.name, (extensionContext, extension) => {
|
|
|
|
+ const promises = new Array<Promise<any>>();
|
|
|
|
+
|
|
|
|
+ return this._loader.loadNodeAsync(extensionContext, node, babylonMesh => {
|
|
|
|
+ for (const emitterIndex of extension.emitters) {
|
|
|
|
+ const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);
|
|
|
|
+ promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {
|
|
|
|
+ for (const sound of emitter._babylonSounds) {
|
|
|
|
+ sound.attachToMesh(babylonMesh);
|
|
|
|
+ if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
|
|
|
|
+ sound.setLocalDirectionToMesh(Vector3.Forward());
|
|
|
|
+ sound.setDirectionalCone(
|
|
|
|
+ 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),
|
|
|
|
+ 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),
|
|
|
|
+ 0);
|
|
|
|
+ }
|
|
|
|
+ }
|
|
|
|
+ }));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ assign(babylonMesh);
|
|
|
|
+ }).then(babylonMesh => {
|
|
|
|
+ return Promise.all(promises).then(() => {
|
|
|
|
+ return babylonMesh;
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /** @hidden */
|
|
|
|
+ public loadAnimationAsync(context: string, animation: ILoaderAnimation): Nullable<Promise<AnimationGroup>> {
|
|
|
|
+ return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {
|
|
|
|
+ return this._loader.loadAnimationAsync(context, animation).then(babylonAnimationGroup => {
|
|
|
|
+ const promises = new Array<Promise<any>>();
|
|
|
|
+
|
|
|
|
+ ArrayItem.Assign(extension.events);
|
|
|
|
+ for (const event of extension.events) {
|
|
|
|
+ promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ return Promise.all(promises).then(() => {
|
|
|
|
+ return babylonAnimationGroup;
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ });
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {
|
|
if (clip._objectURL) {
|
|
if (clip._objectURL) {
|
|
return clip._objectURL;
|
|
return clip._objectURL;
|
|
}
|
|
}
|
|
|
|
|
|
let promise: Promise<ArrayBufferView>;
|
|
let promise: Promise<ArrayBufferView>;
|
|
if (clip.uri) {
|
|
if (clip.uri) {
|
|
- promise = this._loader._loadUriAsync(context, clip.uri);
|
|
|
|
|
|
+ promise = this._loader.loadUriAsync(context, clip.uri);
|
|
}
|
|
}
|
|
else {
|
|
else {
|
|
- const bufferView = GLTFLoader._GetProperty(`${context}/bufferView`, this._loader._gltf.bufferViews, clip.bufferView);
|
|
|
|
- promise = this._loader._loadBufferViewAsync(`#/bufferViews/${bufferView._index}`, bufferView);
|
|
|
|
|
|
+ const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);
|
|
|
|
+ promise = this._loader.loadBufferViewAsync(`#/bufferViews/${bufferView.index}`, bufferView);
|
|
}
|
|
}
|
|
|
|
|
|
clip._objectURL = promise.then(data => {
|
|
clip._objectURL = promise.then(data => {
|
|
@@ -106,23 +209,22 @@ module BABYLON.GLTF2.Extensions {
|
|
return clip._objectURL;
|
|
return clip._objectURL;
|
|
}
|
|
}
|
|
|
|
|
|
- private _loadEmitterAsync(context: string, emitter: _ILoaderEmitter): Promise<void> {
|
|
|
|
|
|
+ private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {
|
|
emitter._babylonSounds = emitter._babylonSounds || [];
|
|
emitter._babylonSounds = emitter._babylonSounds || [];
|
|
if (!emitter._babylonData) {
|
|
if (!emitter._babylonData) {
|
|
- const clipPromises = new Array<Promise<void>>();
|
|
|
|
- const name = emitter.name || `emitter${emitter._index}`;
|
|
|
|
|
|
+ const clipPromises = new Array<Promise<any>>();
|
|
|
|
+ const name = emitter.name || `emitter${emitter.index}`;
|
|
const options = {
|
|
const options = {
|
|
loop: false,
|
|
loop: false,
|
|
autoplay: false,
|
|
autoplay: false,
|
|
volume: emitter.volume == undefined ? 1 : emitter.volume,
|
|
volume: emitter.volume == undefined ? 1 : emitter.volume,
|
|
};
|
|
};
|
|
|
|
|
|
- _ArrayItem.Assign(this._clips);
|
|
|
|
for (let i = 0; i < emitter.clips.length; i++) {
|
|
for (let i = 0; i < emitter.clips.length; i++) {
|
|
- const clipContext = `#/extensions/${NAME}/clips`;
|
|
|
|
- const clip = GLTFLoader._GetProperty(clipContext, this._clips, emitter.clips[i].clip);
|
|
|
|
|
|
+ const clipContext = `#/extensions/${this.name}/clips`;
|
|
|
|
+ const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);
|
|
clipPromises.push(this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {
|
|
clipPromises.push(this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {
|
|
- const sound = emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader._babylonScene, null, options);
|
|
|
|
|
|
+ const sound = emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options);
|
|
sound.refDistance = emitter.refDistance || 1;
|
|
sound.refDistance = emitter.refDistance || 1;
|
|
sound.maxDistance = emitter.maxDistance || 256;
|
|
sound.maxDistance = emitter.maxDistance || 256;
|
|
sound.rolloffFactor = emitter.rolloffFactor || 1;
|
|
sound.rolloffFactor = emitter.rolloffFactor || 1;
|
|
@@ -148,129 +250,53 @@ module BABYLON.GLTF2.Extensions {
|
|
return emitter._babylonData.loaded;
|
|
return emitter._babylonData.loaded;
|
|
}
|
|
}
|
|
|
|
|
|
- protected _loadSceneAsync(context: string, scene: _ILoaderScene): Nullable<Promise<void>> {
|
|
|
|
- return this._loadExtensionAsync<_IEmittersReference>(context, scene, (extensionContext, extension) => {
|
|
|
|
- return this._loader._loadSceneAsync(context, scene).then(() => {
|
|
|
|
-
|
|
|
|
- const promises = new Array<Promise<void>>();
|
|
|
|
- _ArrayItem.Assign(this._emitters);
|
|
|
|
- for (const emitterIndex of extension.emitters) {
|
|
|
|
- const emitter = GLTFLoader._GetProperty(`${extensionContext}/emitters`, this._emitters, emitterIndex);
|
|
|
|
- if (emitter.refDistance != undefined || emitter.maxDistance != undefined || emitter.rolloffFactor != undefined ||
|
|
|
|
- emitter.distanceModel != undefined || emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
|
|
|
|
- throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter._index}`, emitter));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return Promise.all(promises).then(() => {});
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected _loadNodeAsync(context: string, node: _ILoaderNode): Nullable<Promise<void>> {
|
|
|
|
- return this._loadExtensionAsync<_IEmittersReference>(context, node, (extensionContext, extension) => {
|
|
|
|
- return this._loader._loadNodeAsync(extensionContext, node).then(() => {
|
|
|
|
-
|
|
|
|
- const promises = new Array<Promise<void>>();
|
|
|
|
- _ArrayItem.Assign(this._emitters);
|
|
|
|
- for (const emitterIndex of extension.emitters) {
|
|
|
|
- const emitter = GLTFLoader._GetProperty(`${extensionContext}/emitters`, this._emitters, emitterIndex);
|
|
|
|
- promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter._index}`, emitter).then(() => {
|
|
|
|
- if (node._babylonMesh) {
|
|
|
|
- for (const sound of emitter._babylonSounds) {
|
|
|
|
- sound.attachToMesh(node._babylonMesh);
|
|
|
|
- if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
|
|
|
|
- sound.setLocalDirectionToMesh(new Vector3(0, 0, 1));
|
|
|
|
- sound.setDirectionalCone(2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),
|
|
|
|
- 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }
|
|
|
|
- }));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return Promise.all(promises).then(() => {});
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- protected _loadAnimationAsync(context: string, animation: _ILoaderAnimation): Nullable<Promise<void>> {
|
|
|
|
- return this._loadExtensionAsync<_ILoaderAnimationEvents>(context, animation, (extensionContext, extension) => {
|
|
|
|
- return this._loader._loadAnimationAsync(extensionContext, animation).then(() => {
|
|
|
|
- const promises = new Array<Promise<void>>();
|
|
|
|
- const babylonAnimationGroup = animation._babylonAnimationGroup!;
|
|
|
|
-
|
|
|
|
- _ArrayItem.Assign(extension.events);
|
|
|
|
- for (const event of extension.events) {
|
|
|
|
- promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event._index}`, context, animation, event, babylonAnimationGroup));
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return Promise.all(promises).then(() => {});
|
|
|
|
- });
|
|
|
|
- });
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private _getEventAction(context:string, sound: WeightedSound, action: _AnimationEventAction, time: number, startOffset?: number): (currentFrame: number) => void {
|
|
|
|
- if (action == _AnimationEventAction.play) {
|
|
|
|
- return (currentFrame: number) => {
|
|
|
|
- const frameOffset = (startOffset || 0) + (currentFrame - time);
|
|
|
|
- sound.play(frameOffset);
|
|
|
|
- };
|
|
|
|
- } else if (action == _AnimationEventAction.stop) {
|
|
|
|
- return (currentFrame: number) => {
|
|
|
|
- sound.stop();
|
|
|
|
- };
|
|
|
|
- } else if (action == _AnimationEventAction.pause) {
|
|
|
|
- return (currentFrame: number) => {
|
|
|
|
- sound.pause();
|
|
|
|
- };
|
|
|
|
- } else {
|
|
|
|
- throw new Error(`${context}: Unsupported action ${action}`);
|
|
|
|
|
|
+ private _getEventAction(context: string, sound: WeightedSound, action: AnimationEventAction, time: number, startOffset?: number): (currentFrame: number) => void {
|
|
|
|
+ switch (action) {
|
|
|
|
+ case AnimationEventAction.play: {
|
|
|
|
+ return (currentFrame: number) => {
|
|
|
|
+ const frameOffset = (startOffset || 0) + (currentFrame - time);
|
|
|
|
+ sound.play(frameOffset);
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ case AnimationEventAction.stop: {
|
|
|
|
+ return (currentFrame: number) => {
|
|
|
|
+ sound.stop();
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ case AnimationEventAction.pause: {
|
|
|
|
+ return (currentFrame: number) => {
|
|
|
|
+ sound.pause();
|
|
|
|
+ };
|
|
|
|
+ }
|
|
|
|
+ default: {
|
|
|
|
+ throw new Error(`${context}: Unsupported action ${action}`);
|
|
|
|
+ }
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
- private _loadAnimationEventAsync(context: string, animationContext: string, animation: _ILoaderAnimation, event: _ILoaderAnimationEvent, babylonAnimationGroup: AnimationGroup): Promise<void> {
|
|
|
|
|
|
+ private _loadAnimationEventAsync(context: string, animationContext: string, animation: ILoaderAnimation, event: ILoaderAnimationEvent, babylonAnimationGroup: AnimationGroup): Promise<void> {
|
|
if (babylonAnimationGroup.targetedAnimations.length == 0) {
|
|
if (babylonAnimationGroup.targetedAnimations.length == 0) {
|
|
return Promise.resolve();
|
|
return Promise.resolve();
|
|
}
|
|
}
|
|
const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
|
|
const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
|
|
const emitterIndex = event.emitter;
|
|
const emitterIndex = event.emitter;
|
|
- const emitter = GLTFLoader._GetProperty(`#/extensions/${NAME}/emitters`, this._emitters, emitterIndex);
|
|
|
|
- return this._loadEmitterAsync(context, emitter).then(()=> {
|
|
|
|
|
|
+ const emitter = ArrayItem.Get(`#/extensions/${this.name}/emitters`, this._emitters, emitterIndex);
|
|
|
|
+ return this._loadEmitterAsync(context, emitter).then(() => {
|
|
const sound = emitter._babylonData!.sound;
|
|
const sound = emitter._babylonData!.sound;
|
|
if (sound) {
|
|
if (sound) {
|
|
var babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));
|
|
var babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));
|
|
babylonAnimation.animation.addEvent(babylonAnimationEvent);
|
|
babylonAnimation.animation.addEvent(babylonAnimationEvent);
|
|
// Make sure all started audio stops when this animation is terminated.
|
|
// Make sure all started audio stops when this animation is terminated.
|
|
- babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {
|
|
|
|
|
|
+ babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {
|
|
sound.stop();
|
|
sound.stop();
|
|
});
|
|
});
|
|
- babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {
|
|
|
|
|
|
+ babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {
|
|
sound.pause();
|
|
sound.pause();
|
|
});
|
|
});
|
|
}
|
|
}
|
|
});
|
|
});
|
|
}
|
|
}
|
|
-
|
|
|
|
- private get _extension(): _IMSFTAudioEmitter {
|
|
|
|
- const extensions = this._loader._gltf.extensions;
|
|
|
|
- if (!extensions || !extensions[this.name]) {
|
|
|
|
- throw new Error(`#/extensions: '${this.name}' not found`);
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- return extensions[this.name] as _IMSFTAudioEmitter;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private get _clips(): Array<_ILoaderClip> {
|
|
|
|
- return this._extension.clips;
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- private get _emitters(): Array<_ILoaderEmitter> {
|
|
|
|
- return this._extension.emitters;
|
|
|
|
- }
|
|
|
|
}
|
|
}
|
|
|
|
|
|
- GLTFLoader._Register(NAME, loader => new MSFT_audio_emitter(loader));
|
|
|
|
|
|
+ GLTFLoader.RegisterExtension(NAME, loader => new MSFT_audio_emitter(loader));
|
|
}
|
|
}
|