@babylonjs/loaders 5.0.0-rc.6 → 5.0.0
Sign up to get free protection for your applications and to get access to all the features.
- package/OBJ/index.d.ts +4 -4
- package/OBJ/index.js +4 -4
- package/OBJ/mtlFileLoader.d.ts +41 -41
- package/OBJ/mtlFileLoader.js +232 -232
- package/OBJ/mtlFileLoader.js.map +1 -1
- package/OBJ/objFileLoader.d.ts +126 -126
- package/OBJ/objFileLoader.js +296 -296
- package/OBJ/objFileLoader.js.map +1 -1
- package/OBJ/objLoadingOptions.d.ts +43 -43
- package/OBJ/objLoadingOptions.js +1 -1
- package/OBJ/objLoadingOptions.js.map +1 -1
- package/OBJ/solidParser.d.ts +154 -154
- package/OBJ/solidParser.js +693 -693
- package/OBJ/solidParser.js.map +1 -1
- package/STL/index.d.ts +1 -1
- package/STL/index.js +1 -1
- package/STL/stlFileLoader.d.ts +64 -64
- package/STL/stlFileLoader.js +233 -233
- package/STL/stlFileLoader.js.map +1 -1
- package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
- package/glTF/1.0/glTFBinaryExtension.js +60 -60
- package/glTF/1.0/glTFBinaryExtension.js.map +1 -1
- package/glTF/1.0/glTFLoader.d.ts +136 -136
- package/glTF/1.0/glTFLoader.js +1814 -1815
- package/glTF/1.0/glTFLoader.js.map +1 -1
- package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
- package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
- package/glTF/1.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/1.0/glTFLoaderUtils.d.ts +63 -62
- package/glTF/1.0/glTFLoaderUtils.js +250 -250
- package/glTF/1.0/glTFLoaderUtils.js.map +1 -1
- package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
- package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -129
- package/glTF/1.0/glTFMaterialsCommonExtension.js.map +1 -1
- package/glTF/1.0/index.d.ts +5 -5
- package/glTF/1.0/index.js +5 -5
- package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -43
- package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -117
- package/glTF/2.0/Extensions/EXT_lights_image_based.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -36
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -88
- package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -34
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -49
- package/glTF/2.0/Extensions/EXT_meshopt_compression.js.map +1 -1
- package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -29
- package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -40
- package/glTF/2.0/Extensions/EXT_texture_webp.js.map +1 -1
- package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -50
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -73
- package/glTF/2.0/Extensions/ExtrasAsMetadata.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -112
- package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -36
- package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -89
- package/glTF/2.0/Extensions/KHR_lights_punctual.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -94
- package/glTF/2.0/Extensions/KHR_materials_clearcoat.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -53
- package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -42
- package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -62
- package/glTF/2.0/Extensions/KHR_materials_ior.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -80
- package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -84
- package/glTF/2.0/Extensions/KHR_materials_sheen.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -74
- package/glTF/2.0/Extensions/KHR_materials_specular.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -83
- package/glTF/2.0/Extensions/KHR_materials_translucency.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -288
- package/glTF/2.0/Extensions/KHR_materials_transmission.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -38
- package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -73
- package/glTF/2.0/Extensions/KHR_materials_unlit.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -87
- package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -254
- package/glTF/2.0/Extensions/KHR_materials_variants.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -39
- package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -85
- package/glTF/2.0/Extensions/KHR_materials_volume.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -22
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -23
- package/glTF/2.0/Extensions/KHR_mesh_quantization.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -29
- package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -40
- package/glTF/2.0/Extensions/KHR_texture_basisu.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -33
- package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -61
- package/glTF/2.0/Extensions/KHR_texture_transform.js.map +1 -1
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -32
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -49
- package/glTF/2.0/Extensions/KHR_xmp_json_ld.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -54
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -240
- package/glTF/2.0/Extensions/MSFT_audio_emitter.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -109
- package/glTF/2.0/Extensions/MSFT_lod.js +369 -369
- package/glTF/2.0/Extensions/MSFT_lod.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
- package/glTF/2.0/Extensions/MSFT_minecraftMesh.js.map +1 -1
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
- package/glTF/2.0/Extensions/MSFT_sRGBFactors.js.map +1 -1
- package/glTF/2.0/Extensions/index.d.ts +26 -26
- package/glTF/2.0/Extensions/index.js +26 -26
- package/glTF/2.0/glTFLoader.d.ts +406 -405
- package/glTF/2.0/glTFLoader.js +2366 -2366
- package/glTF/2.0/glTFLoader.js.map +1 -1
- package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
- package/glTF/2.0/glTFLoaderExtension.js +1 -1
- package/glTF/2.0/glTFLoaderExtension.js.map +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -211
- package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
- package/glTF/2.0/glTFLoaderInterfaces.js.map +1 -1
- package/glTF/2.0/index.d.ts +4 -4
- package/glTF/2.0/index.js +5 -4
- package/glTF/2.0/index.js.map +1 -1
- package/glTF/glTFFileLoader.d.ts +433 -433
- package/glTF/glTFFileLoader.js +927 -927
- package/glTF/glTFFileLoader.js.map +1 -1
- package/glTF/glTFValidation.d.ts +29 -29
- package/glTF/glTFValidation.js +123 -123
- package/glTF/glTFValidation.js.map +1 -1
- package/glTF/index.d.ts +5 -5
- package/glTF/index.js +6 -5
- package/glTF/index.js.map +1 -1
- package/index.d.ts +3 -3
- package/index.js +4 -3
- package/index.js.map +1 -1
- package/legacy/legacy-glTF.d.ts +2 -2
- package/legacy/legacy-glTF.js +18 -18
- package/legacy/legacy-glTF.js.map +1 -1
- package/legacy/legacy-glTF1.d.ts +2 -2
- package/legacy/legacy-glTF1.js +15 -14
- package/legacy/legacy-glTF1.js.map +1 -1
- package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF1FileLoader.js +3 -3
- package/legacy/legacy-glTF1FileLoader.js.map +1 -1
- package/legacy/legacy-glTF2.d.ts +2 -2
- package/legacy/legacy-glTF2.js +33 -32
- package/legacy/legacy-glTF2.js.map +1 -1
- package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
- package/legacy/legacy-glTF2FileLoader.js +3 -3
- package/legacy/legacy-glTF2FileLoader.js.map +1 -1
- package/legacy/legacy-glTFFileLoader.d.ts +3 -3
- package/legacy/legacy-glTFFileLoader.js +4 -4
- package/legacy/legacy-glTFFileLoader.js.map +1 -1
- package/legacy/legacy-objFileLoader.d.ts +1 -1
- package/legacy/legacy-objFileLoader.js +13 -12
- package/legacy/legacy-objFileLoader.js.map +1 -1
- package/legacy/legacy-stlFileLoader.d.ts +1 -1
- package/legacy/legacy-stlFileLoader.js +13 -12
- package/legacy/legacy-stlFileLoader.js.map +1 -1
- package/legacy/legacy.d.ts +6 -6
- package/legacy/legacy.js +8 -7
- package/legacy/legacy.js.map +1 -1
- package/license.md +71 -0
- package/package.json +25 -6
@@ -1,241 +1,241 @@
|
|
1
|
-
import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
|
2
|
-
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
3
|
-
import { AnimationEvent } from "@babylonjs/core/Animations/animationEvent.js";
|
4
|
-
import { Sound } from "@babylonjs/core/Audio/sound.js";
|
5
|
-
import { WeightedSound } from "@babylonjs/core/Audio/weightedsound.js";
|
6
|
-
import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
|
7
|
-
var NAME = "MSFT_audio_emitter";
|
8
|
-
/**
|
9
|
-
* [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
|
10
|
-
*/
|
11
|
-
var MSFT_audio_emitter = /** @class */ (function () {
|
12
|
-
/**
|
13
|
-
* @param loader
|
14
|
-
* @hidden
|
15
|
-
*/
|
16
|
-
function MSFT_audio_emitter(loader) {
|
17
|
-
/**
|
18
|
-
* The name of this extension.
|
19
|
-
*/
|
20
|
-
this.name = NAME;
|
21
|
-
this._loader = loader;
|
22
|
-
this.enabled = this._loader.isExtensionUsed(NAME);
|
23
|
-
}
|
24
|
-
/** @hidden */
|
25
|
-
MSFT_audio_emitter.prototype.dispose = function () {
|
26
|
-
this._loader = null;
|
27
|
-
this._clips = null;
|
28
|
-
this._emitters = null;
|
29
|
-
};
|
30
|
-
/** @hidden */
|
31
|
-
MSFT_audio_emitter.prototype.onLoading = function () {
|
32
|
-
var extensions = this._loader.gltf.extensions;
|
33
|
-
if (extensions && extensions[this.name]) {
|
34
|
-
var extension = extensions[this.name];
|
35
|
-
this._clips = extension.clips;
|
36
|
-
this._emitters = extension.emitters;
|
37
|
-
ArrayItem.Assign(this._clips);
|
38
|
-
ArrayItem.Assign(this._emitters);
|
39
|
-
}
|
40
|
-
};
|
41
|
-
/**
|
42
|
-
* @param context
|
43
|
-
* @param scene
|
44
|
-
* @hidden
|
45
|
-
*/
|
46
|
-
MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
|
47
|
-
var _this = this;
|
48
|
-
return GLTFLoader.LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
|
49
|
-
var promises = new Array();
|
50
|
-
promises.push(_this._loader.loadSceneAsync(context, scene));
|
51
|
-
for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
|
52
|
-
var emitterIndex = _a[_i];
|
53
|
-
var emitter = ArrayItem.Get("".concat(extensionContext, "/emitters"), _this._emitters, emitterIndex);
|
54
|
-
if (emitter.refDistance != undefined ||
|
55
|
-
emitter.maxDistance != undefined ||
|
56
|
-
emitter.rolloffFactor != undefined ||
|
57
|
-
emitter.distanceModel != undefined ||
|
58
|
-
emitter.innerAngle != undefined ||
|
59
|
-
emitter.outerAngle != undefined) {
|
60
|
-
throw new Error("".concat(extensionContext, ": Direction or Distance properties are not allowed on emitters attached to a scene"));
|
61
|
-
}
|
62
|
-
promises.push(_this._loadEmitterAsync("".concat(extensionContext, "/emitters/").concat(emitter.index), emitter));
|
63
|
-
}
|
64
|
-
return Promise.all(promises).then(function () { });
|
65
|
-
});
|
66
|
-
};
|
67
|
-
/**
|
68
|
-
* @param context
|
69
|
-
* @param node
|
70
|
-
* @param assign
|
71
|
-
* @hidden
|
72
|
-
*/
|
73
|
-
MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
|
74
|
-
var _this = this;
|
75
|
-
return GLTFLoader.LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
|
76
|
-
var promises = new Array();
|
77
|
-
return _this._loader
|
78
|
-
.loadNodeAsync(extensionContext, node, function (babylonMesh) {
|
79
|
-
var _loop_1 = function (emitterIndex) {
|
80
|
-
var emitter = ArrayItem.Get("".concat(extensionContext, "/emitters"), _this._emitters, emitterIndex);
|
81
|
-
promises.push(_this._loadEmitterAsync("".concat(extensionContext, "/emitters/").concat(emitter.index), emitter).then(function () {
|
82
|
-
for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
|
83
|
-
var sound = _a[_i];
|
84
|
-
sound.attachToMesh(babylonMesh);
|
85
|
-
if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
|
86
|
-
sound.setLocalDirectionToMesh(Vector3.Forward());
|
87
|
-
sound.setDirectionalCone(2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
|
88
|
-
}
|
89
|
-
}
|
90
|
-
}));
|
91
|
-
};
|
92
|
-
for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
|
93
|
-
var emitterIndex = _a[_i];
|
94
|
-
_loop_1(emitterIndex);
|
95
|
-
}
|
96
|
-
assign(babylonMesh);
|
97
|
-
})
|
98
|
-
.then(function (babylonMesh) {
|
99
|
-
return Promise.all(promises).then(function () {
|
100
|
-
return babylonMesh;
|
101
|
-
});
|
102
|
-
});
|
103
|
-
});
|
104
|
-
};
|
105
|
-
/**
|
106
|
-
* @param context
|
107
|
-
* @param animation
|
108
|
-
* @hidden
|
109
|
-
*/
|
110
|
-
MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
|
111
|
-
var _this = this;
|
112
|
-
return GLTFLoader.LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
|
113
|
-
return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
|
114
|
-
var promises = new Array();
|
115
|
-
ArrayItem.Assign(extension.events);
|
116
|
-
for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
|
117
|
-
var event_1 = _a[_i];
|
118
|
-
promises.push(_this._loadAnimationEventAsync("".concat(extensionContext, "/events/").concat(event_1.index), context, animation, event_1, babylonAnimationGroup));
|
119
|
-
}
|
120
|
-
return Promise.all(promises).then(function () {
|
121
|
-
return babylonAnimationGroup;
|
122
|
-
});
|
123
|
-
});
|
124
|
-
});
|
125
|
-
};
|
126
|
-
MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
|
127
|
-
if (clip._objectURL) {
|
128
|
-
return clip._objectURL;
|
129
|
-
}
|
130
|
-
var promise;
|
131
|
-
if (clip.uri) {
|
132
|
-
promise = this._loader.loadUriAsync(context, clip, clip.uri);
|
133
|
-
}
|
134
|
-
else {
|
135
|
-
var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._loader.gltf.bufferViews, clip.bufferView);
|
136
|
-
promise = this._loader.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView);
|
137
|
-
}
|
138
|
-
clip._objectURL = promise.then(function (data) {
|
139
|
-
return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
|
140
|
-
});
|
141
|
-
return clip._objectURL;
|
142
|
-
};
|
143
|
-
MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
|
144
|
-
var _this = this;
|
145
|
-
emitter._babylonSounds = emitter._babylonSounds || [];
|
146
|
-
if (!emitter._babylonData) {
|
147
|
-
var clipPromises = new Array();
|
148
|
-
var name_1 = emitter.name || "emitter".concat(emitter.index);
|
149
|
-
var options_1 = {
|
150
|
-
loop: false,
|
151
|
-
autoplay: false,
|
152
|
-
volume: emitter.volume == undefined ? 1 : emitter.volume,
|
153
|
-
};
|
154
|
-
var _loop_2 = function (i) {
|
155
|
-
var clipContext = "/extensions/".concat(this_1.name, "/clips");
|
156
|
-
var clip = ArrayItem.Get(clipContext, this_1._clips, emitter.clips[i].clip);
|
157
|
-
clipPromises.push(this_1._loadClipAsync("".concat(clipContext, "/").concat(emitter.clips[i].clip), clip).then(function (objectURL) {
|
158
|
-
var sound = (emitter._babylonSounds[i] = new Sound(name_1, objectURL, _this._loader.babylonScene, null, options_1));
|
159
|
-
sound.refDistance = emitter.refDistance || 1;
|
160
|
-
sound.maxDistance = emitter.maxDistance || 256;
|
161
|
-
sound.rolloffFactor = emitter.rolloffFactor || 1;
|
162
|
-
sound.distanceModel = emitter.distanceModel || "exponential";
|
163
|
-
}));
|
164
|
-
};
|
165
|
-
var this_1 = this;
|
166
|
-
for (var i = 0; i < emitter.clips.length; i++) {
|
167
|
-
_loop_2(i);
|
168
|
-
}
|
169
|
-
var promise = Promise.all(clipPromises).then(function () {
|
170
|
-
var weights = emitter.clips.map(function (clip) {
|
171
|
-
return clip.weight || 1;
|
172
|
-
});
|
173
|
-
var weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);
|
174
|
-
if (emitter.innerAngle) {
|
175
|
-
weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);
|
176
|
-
}
|
177
|
-
if (emitter.outerAngle) {
|
178
|
-
weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);
|
179
|
-
}
|
180
|
-
if (emitter.volume) {
|
181
|
-
weightedSound.volume = emitter.volume;
|
182
|
-
}
|
183
|
-
emitter._babylonData.sound = weightedSound;
|
184
|
-
});
|
185
|
-
emitter._babylonData = {
|
186
|
-
loaded: promise,
|
187
|
-
};
|
188
|
-
}
|
189
|
-
return emitter._babylonData.loaded;
|
190
|
-
};
|
191
|
-
MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
|
192
|
-
switch (action) {
|
193
|
-
case "play" /* play */: {
|
194
|
-
return function (currentFrame) {
|
195
|
-
var frameOffset = (startOffset || 0) + (currentFrame - time);
|
196
|
-
sound.play(frameOffset);
|
197
|
-
};
|
198
|
-
}
|
199
|
-
case "stop" /* stop */: {
|
200
|
-
return function () {
|
201
|
-
sound.stop();
|
202
|
-
};
|
203
|
-
}
|
204
|
-
case "pause" /* pause */: {
|
205
|
-
return function () {
|
206
|
-
sound.pause();
|
207
|
-
};
|
208
|
-
}
|
209
|
-
default: {
|
210
|
-
throw new Error("".concat(context, ": Unsupported action ").concat(action));
|
211
|
-
}
|
212
|
-
}
|
213
|
-
};
|
214
|
-
MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
|
215
|
-
var _this = this;
|
216
|
-
if (babylonAnimationGroup.targetedAnimations.length == 0) {
|
217
|
-
return Promise.resolve();
|
218
|
-
}
|
219
|
-
var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
|
220
|
-
var emitterIndex = event.emitter;
|
221
|
-
var emitter = ArrayItem.Get("/extensions/".concat(this.name, "/emitters"), this._emitters, emitterIndex);
|
222
|
-
return this._loadEmitterAsync(context, emitter).then(function () {
|
223
|
-
var sound = emitter._babylonData.sound;
|
224
|
-
if (sound) {
|
225
|
-
var babylonAnimationEvent = new AnimationEvent(event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
|
226
|
-
babylonAnimation.animation.addEvent(babylonAnimationEvent);
|
227
|
-
// Make sure all started audio stops when this animation is terminated.
|
228
|
-
babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
|
229
|
-
sound.stop();
|
230
|
-
});
|
231
|
-
babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
|
232
|
-
sound.pause();
|
233
|
-
});
|
234
|
-
}
|
235
|
-
});
|
236
|
-
};
|
237
|
-
return MSFT_audio_emitter;
|
238
|
-
}());
|
239
|
-
export { MSFT_audio_emitter };
|
240
|
-
GLTFLoader.RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
|
1
|
+
import { Vector3 } from "@babylonjs/core/Maths/math.vector.js";
|
2
|
+
import { Tools } from "@babylonjs/core/Misc/tools.js";
|
3
|
+
import { AnimationEvent } from "@babylonjs/core/Animations/animationEvent.js";
|
4
|
+
import { Sound } from "@babylonjs/core/Audio/sound.js";
|
5
|
+
import { WeightedSound } from "@babylonjs/core/Audio/weightedsound.js";
|
6
|
+
import { GLTFLoader, ArrayItem } from "../glTFLoader.js";
|
7
|
+
var NAME = "MSFT_audio_emitter";
|
8
|
+
/**
|
9
|
+
* [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)
|
10
|
+
*/
|
11
|
+
var MSFT_audio_emitter = /** @class */ (function () {
|
12
|
+
/**
|
13
|
+
* @param loader
|
14
|
+
* @hidden
|
15
|
+
*/
|
16
|
+
function MSFT_audio_emitter(loader) {
|
17
|
+
/**
|
18
|
+
* The name of this extension.
|
19
|
+
*/
|
20
|
+
this.name = NAME;
|
21
|
+
this._loader = loader;
|
22
|
+
this.enabled = this._loader.isExtensionUsed(NAME);
|
23
|
+
}
|
24
|
+
/** @hidden */
|
25
|
+
MSFT_audio_emitter.prototype.dispose = function () {
|
26
|
+
this._loader = null;
|
27
|
+
this._clips = null;
|
28
|
+
this._emitters = null;
|
29
|
+
};
|
30
|
+
/** @hidden */
|
31
|
+
MSFT_audio_emitter.prototype.onLoading = function () {
|
32
|
+
var extensions = this._loader.gltf.extensions;
|
33
|
+
if (extensions && extensions[this.name]) {
|
34
|
+
var extension = extensions[this.name];
|
35
|
+
this._clips = extension.clips;
|
36
|
+
this._emitters = extension.emitters;
|
37
|
+
ArrayItem.Assign(this._clips);
|
38
|
+
ArrayItem.Assign(this._emitters);
|
39
|
+
}
|
40
|
+
};
|
41
|
+
/**
|
42
|
+
* @param context
|
43
|
+
* @param scene
|
44
|
+
* @hidden
|
45
|
+
*/
|
46
|
+
MSFT_audio_emitter.prototype.loadSceneAsync = function (context, scene) {
|
47
|
+
var _this = this;
|
48
|
+
return GLTFLoader.LoadExtensionAsync(context, scene, this.name, function (extensionContext, extension) {
|
49
|
+
var promises = new Array();
|
50
|
+
promises.push(_this._loader.loadSceneAsync(context, scene));
|
51
|
+
for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
|
52
|
+
var emitterIndex = _a[_i];
|
53
|
+
var emitter = ArrayItem.Get("".concat(extensionContext, "/emitters"), _this._emitters, emitterIndex);
|
54
|
+
if (emitter.refDistance != undefined ||
|
55
|
+
emitter.maxDistance != undefined ||
|
56
|
+
emitter.rolloffFactor != undefined ||
|
57
|
+
emitter.distanceModel != undefined ||
|
58
|
+
emitter.innerAngle != undefined ||
|
59
|
+
emitter.outerAngle != undefined) {
|
60
|
+
throw new Error("".concat(extensionContext, ": Direction or Distance properties are not allowed on emitters attached to a scene"));
|
61
|
+
}
|
62
|
+
promises.push(_this._loadEmitterAsync("".concat(extensionContext, "/emitters/").concat(emitter.index), emitter));
|
63
|
+
}
|
64
|
+
return Promise.all(promises).then(function () { });
|
65
|
+
});
|
66
|
+
};
|
67
|
+
/**
|
68
|
+
* @param context
|
69
|
+
* @param node
|
70
|
+
* @param assign
|
71
|
+
* @hidden
|
72
|
+
*/
|
73
|
+
MSFT_audio_emitter.prototype.loadNodeAsync = function (context, node, assign) {
|
74
|
+
var _this = this;
|
75
|
+
return GLTFLoader.LoadExtensionAsync(context, node, this.name, function (extensionContext, extension) {
|
76
|
+
var promises = new Array();
|
77
|
+
return _this._loader
|
78
|
+
.loadNodeAsync(extensionContext, node, function (babylonMesh) {
|
79
|
+
var _loop_1 = function (emitterIndex) {
|
80
|
+
var emitter = ArrayItem.Get("".concat(extensionContext, "/emitters"), _this._emitters, emitterIndex);
|
81
|
+
promises.push(_this._loadEmitterAsync("".concat(extensionContext, "/emitters/").concat(emitter.index), emitter).then(function () {
|
82
|
+
for (var _i = 0, _a = emitter._babylonSounds; _i < _a.length; _i++) {
|
83
|
+
var sound = _a[_i];
|
84
|
+
sound.attachToMesh(babylonMesh);
|
85
|
+
if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
|
86
|
+
sound.setLocalDirectionToMesh(Vector3.Forward());
|
87
|
+
sound.setDirectionalCone(2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
|
88
|
+
}
|
89
|
+
}
|
90
|
+
}));
|
91
|
+
};
|
92
|
+
for (var _i = 0, _a = extension.emitters; _i < _a.length; _i++) {
|
93
|
+
var emitterIndex = _a[_i];
|
94
|
+
_loop_1(emitterIndex);
|
95
|
+
}
|
96
|
+
assign(babylonMesh);
|
97
|
+
})
|
98
|
+
.then(function (babylonMesh) {
|
99
|
+
return Promise.all(promises).then(function () {
|
100
|
+
return babylonMesh;
|
101
|
+
});
|
102
|
+
});
|
103
|
+
});
|
104
|
+
};
|
105
|
+
/**
|
106
|
+
* @param context
|
107
|
+
* @param animation
|
108
|
+
* @hidden
|
109
|
+
*/
|
110
|
+
MSFT_audio_emitter.prototype.loadAnimationAsync = function (context, animation) {
|
111
|
+
var _this = this;
|
112
|
+
return GLTFLoader.LoadExtensionAsync(context, animation, this.name, function (extensionContext, extension) {
|
113
|
+
return _this._loader.loadAnimationAsync(context, animation).then(function (babylonAnimationGroup) {
|
114
|
+
var promises = new Array();
|
115
|
+
ArrayItem.Assign(extension.events);
|
116
|
+
for (var _i = 0, _a = extension.events; _i < _a.length; _i++) {
|
117
|
+
var event_1 = _a[_i];
|
118
|
+
promises.push(_this._loadAnimationEventAsync("".concat(extensionContext, "/events/").concat(event_1.index), context, animation, event_1, babylonAnimationGroup));
|
119
|
+
}
|
120
|
+
return Promise.all(promises).then(function () {
|
121
|
+
return babylonAnimationGroup;
|
122
|
+
});
|
123
|
+
});
|
124
|
+
});
|
125
|
+
};
|
126
|
+
MSFT_audio_emitter.prototype._loadClipAsync = function (context, clip) {
|
127
|
+
if (clip._objectURL) {
|
128
|
+
return clip._objectURL;
|
129
|
+
}
|
130
|
+
var promise;
|
131
|
+
if (clip.uri) {
|
132
|
+
promise = this._loader.loadUriAsync(context, clip, clip.uri);
|
133
|
+
}
|
134
|
+
else {
|
135
|
+
var bufferView = ArrayItem.Get("".concat(context, "/bufferView"), this._loader.gltf.bufferViews, clip.bufferView);
|
136
|
+
promise = this._loader.loadBufferViewAsync("/bufferViews/".concat(bufferView.index), bufferView);
|
137
|
+
}
|
138
|
+
clip._objectURL = promise.then(function (data) {
|
139
|
+
return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
|
140
|
+
});
|
141
|
+
return clip._objectURL;
|
142
|
+
};
|
143
|
+
MSFT_audio_emitter.prototype._loadEmitterAsync = function (context, emitter) {
|
144
|
+
var _this = this;
|
145
|
+
emitter._babylonSounds = emitter._babylonSounds || [];
|
146
|
+
if (!emitter._babylonData) {
|
147
|
+
var clipPromises = new Array();
|
148
|
+
var name_1 = emitter.name || "emitter".concat(emitter.index);
|
149
|
+
var options_1 = {
|
150
|
+
loop: false,
|
151
|
+
autoplay: false,
|
152
|
+
volume: emitter.volume == undefined ? 1 : emitter.volume,
|
153
|
+
};
|
154
|
+
var _loop_2 = function (i) {
|
155
|
+
var clipContext = "/extensions/".concat(this_1.name, "/clips");
|
156
|
+
var clip = ArrayItem.Get(clipContext, this_1._clips, emitter.clips[i].clip);
|
157
|
+
clipPromises.push(this_1._loadClipAsync("".concat(clipContext, "/").concat(emitter.clips[i].clip), clip).then(function (objectURL) {
|
158
|
+
var sound = (emitter._babylonSounds[i] = new Sound(name_1, objectURL, _this._loader.babylonScene, null, options_1));
|
159
|
+
sound.refDistance = emitter.refDistance || 1;
|
160
|
+
sound.maxDistance = emitter.maxDistance || 256;
|
161
|
+
sound.rolloffFactor = emitter.rolloffFactor || 1;
|
162
|
+
sound.distanceModel = emitter.distanceModel || "exponential";
|
163
|
+
}));
|
164
|
+
};
|
165
|
+
var this_1 = this;
|
166
|
+
for (var i = 0; i < emitter.clips.length; i++) {
|
167
|
+
_loop_2(i);
|
168
|
+
}
|
169
|
+
var promise = Promise.all(clipPromises).then(function () {
|
170
|
+
var weights = emitter.clips.map(function (clip) {
|
171
|
+
return clip.weight || 1;
|
172
|
+
});
|
173
|
+
var weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);
|
174
|
+
if (emitter.innerAngle) {
|
175
|
+
weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);
|
176
|
+
}
|
177
|
+
if (emitter.outerAngle) {
|
178
|
+
weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);
|
179
|
+
}
|
180
|
+
if (emitter.volume) {
|
181
|
+
weightedSound.volume = emitter.volume;
|
182
|
+
}
|
183
|
+
emitter._babylonData.sound = weightedSound;
|
184
|
+
});
|
185
|
+
emitter._babylonData = {
|
186
|
+
loaded: promise,
|
187
|
+
};
|
188
|
+
}
|
189
|
+
return emitter._babylonData.loaded;
|
190
|
+
};
|
191
|
+
MSFT_audio_emitter.prototype._getEventAction = function (context, sound, action, time, startOffset) {
|
192
|
+
switch (action) {
|
193
|
+
case "play" /* play */: {
|
194
|
+
return function (currentFrame) {
|
195
|
+
var frameOffset = (startOffset || 0) + (currentFrame - time);
|
196
|
+
sound.play(frameOffset);
|
197
|
+
};
|
198
|
+
}
|
199
|
+
case "stop" /* stop */: {
|
200
|
+
return function () {
|
201
|
+
sound.stop();
|
202
|
+
};
|
203
|
+
}
|
204
|
+
case "pause" /* pause */: {
|
205
|
+
return function () {
|
206
|
+
sound.pause();
|
207
|
+
};
|
208
|
+
}
|
209
|
+
default: {
|
210
|
+
throw new Error("".concat(context, ": Unsupported action ").concat(action));
|
211
|
+
}
|
212
|
+
}
|
213
|
+
};
|
214
|
+
MSFT_audio_emitter.prototype._loadAnimationEventAsync = function (context, animationContext, animation, event, babylonAnimationGroup) {
|
215
|
+
var _this = this;
|
216
|
+
if (babylonAnimationGroup.targetedAnimations.length == 0) {
|
217
|
+
return Promise.resolve();
|
218
|
+
}
|
219
|
+
var babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
|
220
|
+
var emitterIndex = event.emitter;
|
221
|
+
var emitter = ArrayItem.Get("/extensions/".concat(this.name, "/emitters"), this._emitters, emitterIndex);
|
222
|
+
return this._loadEmitterAsync(context, emitter).then(function () {
|
223
|
+
var sound = emitter._babylonData.sound;
|
224
|
+
if (sound) {
|
225
|
+
var babylonAnimationEvent = new AnimationEvent(event.time, _this._getEventAction(context, sound, event.action, event.time, event.startOffset));
|
226
|
+
babylonAnimation.animation.addEvent(babylonAnimationEvent);
|
227
|
+
// Make sure all started audio stops when this animation is terminated.
|
228
|
+
babylonAnimationGroup.onAnimationGroupEndObservable.add(function () {
|
229
|
+
sound.stop();
|
230
|
+
});
|
231
|
+
babylonAnimationGroup.onAnimationGroupPauseObservable.add(function () {
|
232
|
+
sound.pause();
|
233
|
+
});
|
234
|
+
}
|
235
|
+
});
|
236
|
+
};
|
237
|
+
return MSFT_audio_emitter;
|
238
|
+
}());
|
239
|
+
export { MSFT_audio_emitter };
|
240
|
+
GLTFLoader.RegisterExtension(NAME, function (loader) { return new MSFT_audio_emitter(loader); });
|
241
241
|
//# sourceMappingURL=MSFT_audio_emitter.js.map
|
@@ -1 +1 @@
|
|
1
|
-
{"version":3,"file":"MSFT_audio_emitter.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/MSFT_audio_emitter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAEhE,OAAO,EAAE,KAAK,EAAE,uCAAyB;AACzC,OAAO,EAAE,aAAa,EAAE,+CAAiC;AAIzD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAStD,IAAM,IAAI,GAAG,oBAAoB,CAAC;AAyBlC;;GAEG;AACH;IAeI;;;OAGG;IACH,4BAAY,MAAkB;QAlB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAgBxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,cAAc;IACP,oCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,MAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,SAAiB,GAAG,IAA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CAAC,IAAI,cAAW,EAAE,IAAI,CAAC,SAAS,EAAE,YAAY,CAAC,CAAC;QACjG,OAAO,IAAI,CAAC,iBAAiB,CAAC,OAAO,EAAE,OAAO,CAAC,CAAC,IAAI,CAAC;YACjD,IAAM,KAAK,GAAG,OAAO,CAAC,YAAa,CAAC,KAAK,CAAC;YAC1C,IAAI,KAAK,EAAE;gBACP,IAAM,qBAAqB,GAAG,IAAI,cAAc,CAAC,KAAK,CAAC,IAAI,EAAE,KAAI,CAAC,eAAe,CAAC,OAAO,EAAE,KAAK,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;gBAChJ,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;gBAC3D,uEAAuE;gBACvE,qBAAqB,CAAC,6BAA6B,CAAC,GAAG,CAAC;oBACpD,KAAK,CAAC,IAAI,EAAE,CAAC;gBACjB,CAAC,CAAC,CAAC;gBACH,qBAAqB,CAAC,+BAA+B,CAAC,GAAG,CAAC;oBACtD,KAAK,CAAC,KAAK,EAAE,CAAC;gBAClB,CAAC,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACL,yBAAC;AAAD,CAAC,AA3QD,IA2QC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAA9B,CAA8B,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport { AnimationEvent } from \"core/Animations/animationEvent\";\r\nimport { TransformNode } from \"core/Meshes/transformNode\";\r\nimport { Sound } from \"core/Audio/sound\";\r\nimport { WeightedSound } from \"core/Audio/weightedsound\";\r\n\r\nimport { IArrayItem, IScene, INode, IAnimation } from \"../glTFLoaderInterfaces\";\r\nimport { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport {\r\n IMSFTAudioEmitter_Clip,\r\n IMSFTAudioEmitter_Emitter,\r\n IMSFTAudioEmitter_EmittersReference,\r\n IMSFTAudioEmitter_AnimationEvent,\r\n IMSFTAudioEmitter_AnimationEventAction,\r\n} from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"MSFT_audio_emitter\";\r\n\r\ninterface ILoaderClip extends IMSFTAudioEmitter_Clip, IArrayItem {\r\n _objectURL?: Promise<string>;\r\n}\r\n\r\ninterface ILoaderEmitter extends IMSFTAudioEmitter_Emitter, IArrayItem {\r\n _babylonData?: {\r\n sound?: WeightedSound;\r\n loaded: Promise<void>;\r\n };\r\n _babylonSounds: Sound[];\r\n}\r\n\r\ninterface IMSFTAudioEmitter {\r\n clips: ILoaderClip[];\r\n emitters: ILoaderEmitter[];\r\n}\r\n\r\ninterface ILoaderAnimationEvent extends IMSFTAudioEmitter_AnimationEvent, IArrayItem {}\r\n\r\ninterface ILoaderAnimationEvents {\r\n events: ILoaderAnimationEvent[];\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)\r\n */\r\nexport class MSFT_audio_emitter implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _clips: Array<ILoaderClip>;\r\n private _emitters: Array<ILoaderEmitter>;\r\n\r\n /**\r\n * @param loader\r\n * @hidden\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n (this._clips as any) = null;\r\n (this._emitters as any) = null;\r\n }\r\n\r\n /** @hidden */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IMSFTAudioEmitter;\r\n\r\n this._clips = extension.clips;\r\n this._emitters = extension.emitters;\r\n\r\n ArrayItem.Assign(this._clips);\r\n ArrayItem.Assign(this._emitters);\r\n }\r\n }\r\n\r\n /**\r\n * @param context\r\n * @param scene\r\n * @hidden\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n if (\r\n emitter.refDistance != undefined ||\r\n emitter.maxDistance != undefined ||\r\n emitter.rolloffFactor != undefined ||\r\n emitter.distanceModel != undefined ||\r\n emitter.innerAngle != undefined ||\r\n emitter.outerAngle != undefined\r\n ) {\r\n throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);\r\n }\r\n\r\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n /**\r\n * @param context\r\n * @param node\r\n * @param assign\r\n * @hidden\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n return this._loader\r\n .loadNodeAsync(extensionContext, node, (babylonMesh) => {\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n promises.push(\r\n this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {\r\n for (const sound of emitter._babylonSounds) {\r\n sound.attachToMesh(babylonMesh);\r\n if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\r\n sound.setLocalDirectionToMesh(Vector3.Forward());\r\n sound.setDirectionalCone(\r\n 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),\r\n 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),\r\n 0\r\n );\r\n }\r\n }\r\n })\r\n );\r\n }\r\n\r\n assign(babylonMesh);\r\n })\r\n .then((babylonMesh) => {\r\n return Promise.all(promises).then(() => {\r\n return babylonMesh;\r\n });\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * @param context\r\n * @param animation\r\n * @hidden\r\n */\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {\r\n return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n ArrayItem.Assign(extension.events);\r\n for (const event of extension.events) {\r\n promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return babylonAnimationGroup;\r\n });\r\n });\r\n });\r\n }\r\n\r\n private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {\r\n if (clip._objectURL) {\r\n return clip._objectURL;\r\n }\r\n\r\n let promise: Promise<ArrayBufferView>;\r\n if (clip.uri) {\r\n promise = this._loader.loadUriAsync(context, clip, clip.uri);\r\n } else {\r\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);\r\n promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\r\n }\r\n\r\n clip._objectURL = promise.then((data) => {\r\n return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));\r\n });\r\n\r\n return clip._objectURL;\r\n }\r\n\r\n private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {\r\n emitter._babylonSounds = emitter._babylonSounds || [];\r\n if (!emitter._babylonData) {\r\n const clipPromises = new Array<Promise<any>>();\r\n const name = emitter.name || `emitter${emitter.index}`;\r\n const options = {\r\n loop: false,\r\n autoplay: false,\r\n volume: emitter.volume == undefined ? 1 : emitter.volume,\r\n };\r\n\r\n for (let i = 0; i < emitter.clips.length; i++) {\r\n const clipContext = `/extensions/${this.name}/clips`;\r\n const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);\r\n clipPromises.push(\r\n this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {\r\n const sound = (emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options));\r\n sound.refDistance = emitter.refDistance || 1;\r\n sound.maxDistance = emitter.maxDistance || 256;\r\n sound.rolloffFactor = emitter.rolloffFactor || 1;\r\n sound.distanceModel = emitter.distanceModel || \"exponential\";\r\n })\r\n );\r\n }\r\n\r\n const promise = Promise.all(clipPromises).then(() => {\r\n const weights = emitter.clips.map((clip) => {\r\n return clip.weight || 1;\r\n });\r\n const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);\r\n if (emitter.innerAngle) {\r\n weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);\r\n }\r\n if (emitter.outerAngle) {\r\n weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);\r\n }\r\n if (emitter.volume) {\r\n weightedSound.volume = emitter.volume;\r\n }\r\n emitter._babylonData!.sound = weightedSound;\r\n });\r\n\r\n emitter._babylonData = {\r\n loaded: promise,\r\n };\r\n }\r\n\r\n return emitter._babylonData.loaded;\r\n }\r\n\r\n private _getEventAction(\r\n context: string,\r\n sound: WeightedSound,\r\n action: IMSFTAudioEmitter_AnimationEventAction,\r\n time: number,\r\n startOffset?: number\r\n ): (currentFrame: number) => void {\r\n switch (action) {\r\n case IMSFTAudioEmitter_AnimationEventAction.play: {\r\n return (currentFrame: number) => {\r\n const frameOffset = (startOffset || 0) + (currentFrame - time);\r\n sound.play(frameOffset);\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.stop: {\r\n return () => {\r\n sound.stop();\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.pause: {\r\n return () => {\r\n sound.pause();\r\n };\r\n }\r\n default: {\r\n throw new Error(`${context}: Unsupported action ${action}`);\r\n }\r\n }\r\n }\r\n\r\n private _loadAnimationEventAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n event: ILoaderAnimationEvent,\r\n babylonAnimationGroup: AnimationGroup\r\n ): Promise<void> {\r\n if (babylonAnimationGroup.targetedAnimations.length == 0) {\r\n return Promise.resolve();\r\n }\r\n const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];\r\n const emitterIndex = event.emitter;\r\n const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);\r\n return this._loadEmitterAsync(context, emitter).then(() => {\r\n const sound = emitter._babylonData!.sound;\r\n if (sound) {\r\n const babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));\r\n babylonAnimation.animation.addEvent(babylonAnimationEvent);\r\n // Make sure all started audio stops when this animation is terminated.\r\n babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {\r\n sound.stop();\r\n });\r\n babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {\r\n sound.pause();\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_audio_emitter(loader));\r\n"]}
|
1
|
+
{"version":3,"file":"MSFT_audio_emitter.js","sourceRoot":"","sources":["../../../../../../../lts/loaders/generated/glTF/2.0/Extensions/MSFT_audio_emitter.ts"],"names":[],"mappings":"AAEA,OAAO,EAAE,OAAO,EAAE,6CAA+B;AACjD,OAAO,EAAE,KAAK,EAAE,sCAAwB;AAExC,OAAO,EAAE,cAAc,EAAE,qDAAuC;AAEhE,OAAO,EAAE,KAAK,EAAE,uCAAyB;AACzC,OAAO,EAAE,aAAa,EAAE,+CAAiC;AAIzD,OAAO,EAAE,UAAU,EAAE,SAAS,EAAE,MAAM,eAAe,CAAC;AAItD,IAAM,IAAI,GAAG,oBAAoB,CAAC;AAyBlC;;GAEG;AACH;IAeI;;;OAGG;IACH,4BAAY,MAAkB;QAlB9B;;WAEG;QACa,SAAI,GAAG,IAAI,CAAC;QAgBxB,IAAI,CAAC,OAAO,GAAG,MAAM,CAAC;QACtB,IAAI,CAAC,OAAO,GAAG,IAAI,CAAC,OAAO,CAAC,eAAe,CAAC,IAAI,CAAC,CAAC;IACtD,CAAC;IAED,cAAc;IACP,oCAAO,GAAd;QACK,IAAI,CAAC,OAAe,GAAG,IAAI,CAAC;QAC5B,IAAI,CAAC,MAAc,GAAG,IAAI,CAAC;QAC3B,IAAI,CAAC,SAAiB,GAAG,IAAI,CAAC;IACnC,CAAC;IAED,cAAc;IACP,sCAAS,GAAhB;QACI,IAAM,UAAU,GAAG,IAAI,CAAC,OAAO,CAAC,IAAI,CAAC,UAAU,CAAC;QAChD,IAAI,UAAU,IAAI,UAAU,CAAC,IAAI,CAAC,IAAI,CAAC,EAAE;YACrC,IAAM,SAAS,GAAG,UAAU,CAAC,IAAI,CAAC,IAAI,CAAsB,CAAC;YAE7D,IAAI,CAAC,MAAM,GAAG,SAAS,CAAC,KAAK,CAAC;YAC9B,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,QAAQ,CAAC;YAEpC,SAAS,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AAC,IAAI,EAAE,KAAK,CAAC,WAAW,CAAC,CAAC,CAAC;gBAChJ,gBAAgB,CAAC,SAAS,CAAC,QAAQ,CAAC,qBAAqB,CAAC,CAAC;gBAC3D,uEAAuE;gBACvE,qBAAqB,CAAC,6BAA6B,CAAC,GAAG,CAAC;oBACpD,KAAK,CAAC,IAAI,EAAE,CAAC;gBACjB,CAAC,CAAC,CAAC;gBACH,qBAAqB,CAAC,+BAA+B,CAAC,GAAG,CAAC;oBACtD,KAAK,CAAC,KAAK,EAAE,CAAC;gBAClB,CAAC,CAAC,CAAC;aACN;QACL,CAAC,CAAC,CAAC;IACP,CAAC;IACL,yBAAC;AAAD,CAAC,AA3QD,IA2QC;;AAED,UAAU,CAAC,iBAAiB,CAAC,IAAI,EAAE,UAAC,MAAM,IAAK,OAAA,IAAI,kBAAkB,CAAC,MAAM,CAAC,EAA9B,CAA8B,CAAC,CAAC","sourcesContent":["/* eslint-disable @typescript-eslint/naming-convention */\r\nimport type { Nullable } from \"core/types\";\r\nimport { Vector3 } from \"core/Maths/math.vector\";\r\nimport { Tools } from \"core/Misc/tools\";\r\nimport type { AnimationGroup } from \"core/Animations/animationGroup\";\r\nimport { AnimationEvent } from \"core/Animations/animationEvent\";\r\nimport type { TransformNode } from \"core/Meshes/transformNode\";\r\nimport { Sound } from \"core/Audio/sound\";\r\nimport { WeightedSound } from \"core/Audio/weightedsound\";\r\n\r\nimport type { IArrayItem, IScene, INode, IAnimation } from \"../glTFLoaderInterfaces\";\r\nimport type { IGLTFLoaderExtension } from \"../glTFLoaderExtension\";\r\nimport { GLTFLoader, ArrayItem } from \"../glTFLoader\";\r\nimport type { IMSFTAudioEmitter_Clip, IMSFTAudioEmitter_Emitter, IMSFTAudioEmitter_EmittersReference, IMSFTAudioEmitter_AnimationEvent } from \"babylonjs-gltf2interface\";\r\nimport { IMSFTAudioEmitter_AnimationEventAction } from \"babylonjs-gltf2interface\";\r\n\r\nconst NAME = \"MSFT_audio_emitter\";\r\n\r\ninterface ILoaderClip extends IMSFTAudioEmitter_Clip, IArrayItem {\r\n _objectURL?: Promise<string>;\r\n}\r\n\r\ninterface ILoaderEmitter extends IMSFTAudioEmitter_Emitter, IArrayItem {\r\n _babylonData?: {\r\n sound?: WeightedSound;\r\n loaded: Promise<void>;\r\n };\r\n _babylonSounds: Sound[];\r\n}\r\n\r\ninterface IMSFTAudioEmitter {\r\n clips: ILoaderClip[];\r\n emitters: ILoaderEmitter[];\r\n}\r\n\r\ninterface ILoaderAnimationEvent extends IMSFTAudioEmitter_AnimationEvent, IArrayItem {}\r\n\r\ninterface ILoaderAnimationEvents {\r\n events: ILoaderAnimationEvent[];\r\n}\r\n\r\n/**\r\n * [Specification](https://github.com/najadojo/glTF/tree/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter)\r\n */\r\nexport class MSFT_audio_emitter implements IGLTFLoaderExtension {\r\n /**\r\n * The name of this extension.\r\n */\r\n public readonly name = NAME;\r\n\r\n /**\r\n * Defines whether this extension is enabled.\r\n */\r\n public enabled: boolean;\r\n\r\n private _loader: GLTFLoader;\r\n private _clips: Array<ILoaderClip>;\r\n private _emitters: Array<ILoaderEmitter>;\r\n\r\n /**\r\n * @param loader\r\n * @hidden\r\n */\r\n constructor(loader: GLTFLoader) {\r\n this._loader = loader;\r\n this.enabled = this._loader.isExtensionUsed(NAME);\r\n }\r\n\r\n /** @hidden */\r\n public dispose() {\r\n (this._loader as any) = null;\r\n (this._clips as any) = null;\r\n (this._emitters as any) = null;\r\n }\r\n\r\n /** @hidden */\r\n public onLoading(): void {\r\n const extensions = this._loader.gltf.extensions;\r\n if (extensions && extensions[this.name]) {\r\n const extension = extensions[this.name] as IMSFTAudioEmitter;\r\n\r\n this._clips = extension.clips;\r\n this._emitters = extension.emitters;\r\n\r\n ArrayItem.Assign(this._clips);\r\n ArrayItem.Assign(this._emitters);\r\n }\r\n }\r\n\r\n /**\r\n * @param context\r\n * @param scene\r\n * @hidden\r\n */\r\n public loadSceneAsync(context: string, scene: IScene): Nullable<Promise<void>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference>(context, scene, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n promises.push(this._loader.loadSceneAsync(context, scene));\r\n\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n if (\r\n emitter.refDistance != undefined ||\r\n emitter.maxDistance != undefined ||\r\n emitter.rolloffFactor != undefined ||\r\n emitter.distanceModel != undefined ||\r\n emitter.innerAngle != undefined ||\r\n emitter.outerAngle != undefined\r\n ) {\r\n throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);\r\n }\r\n\r\n promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));\r\n }\r\n\r\n return Promise.all(promises).then(() => {});\r\n });\r\n }\r\n\r\n /**\r\n * @param context\r\n * @param node\r\n * @param assign\r\n * @hidden\r\n */\r\n public loadNodeAsync(context: string, node: INode, assign: (babylonTransformNode: TransformNode) => void): Nullable<Promise<TransformNode>> {\r\n return GLTFLoader.LoadExtensionAsync<IMSFTAudioEmitter_EmittersReference, TransformNode>(context, node, this.name, (extensionContext, extension) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n return this._loader\r\n .loadNodeAsync(extensionContext, node, (babylonMesh) => {\r\n for (const emitterIndex of extension.emitters) {\r\n const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);\r\n promises.push(\r\n this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {\r\n for (const sound of emitter._babylonSounds) {\r\n sound.attachToMesh(babylonMesh);\r\n if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {\r\n sound.setLocalDirectionToMesh(Vector3.Forward());\r\n sound.setDirectionalCone(\r\n 2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle),\r\n 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle),\r\n 0\r\n );\r\n }\r\n }\r\n })\r\n );\r\n }\r\n\r\n assign(babylonMesh);\r\n })\r\n .then((babylonMesh) => {\r\n return Promise.all(promises).then(() => {\r\n return babylonMesh;\r\n });\r\n });\r\n });\r\n }\r\n\r\n /**\r\n * @param context\r\n * @param animation\r\n * @hidden\r\n */\r\n public loadAnimationAsync(context: string, animation: IAnimation): Nullable<Promise<AnimationGroup>> {\r\n return GLTFLoader.LoadExtensionAsync<ILoaderAnimationEvents, AnimationGroup>(context, animation, this.name, (extensionContext, extension) => {\r\n return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {\r\n const promises = new Array<Promise<any>>();\r\n\r\n ArrayItem.Assign(extension.events);\r\n for (const event of extension.events) {\r\n promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));\r\n }\r\n\r\n return Promise.all(promises).then(() => {\r\n return babylonAnimationGroup;\r\n });\r\n });\r\n });\r\n }\r\n\r\n private _loadClipAsync(context: string, clip: ILoaderClip): Promise<string> {\r\n if (clip._objectURL) {\r\n return clip._objectURL;\r\n }\r\n\r\n let promise: Promise<ArrayBufferView>;\r\n if (clip.uri) {\r\n promise = this._loader.loadUriAsync(context, clip, clip.uri);\r\n } else {\r\n const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);\r\n promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);\r\n }\r\n\r\n clip._objectURL = promise.then((data) => {\r\n return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));\r\n });\r\n\r\n return clip._objectURL;\r\n }\r\n\r\n private _loadEmitterAsync(context: string, emitter: ILoaderEmitter): Promise<void> {\r\n emitter._babylonSounds = emitter._babylonSounds || [];\r\n if (!emitter._babylonData) {\r\n const clipPromises = new Array<Promise<any>>();\r\n const name = emitter.name || `emitter${emitter.index}`;\r\n const options = {\r\n loop: false,\r\n autoplay: false,\r\n volume: emitter.volume == undefined ? 1 : emitter.volume,\r\n };\r\n\r\n for (let i = 0; i < emitter.clips.length; i++) {\r\n const clipContext = `/extensions/${this.name}/clips`;\r\n const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);\r\n clipPromises.push(\r\n this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL: string) => {\r\n const sound = (emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options));\r\n sound.refDistance = emitter.refDistance || 1;\r\n sound.maxDistance = emitter.maxDistance || 256;\r\n sound.rolloffFactor = emitter.rolloffFactor || 1;\r\n sound.distanceModel = emitter.distanceModel || \"exponential\";\r\n })\r\n );\r\n }\r\n\r\n const promise = Promise.all(clipPromises).then(() => {\r\n const weights = emitter.clips.map((clip) => {\r\n return clip.weight || 1;\r\n });\r\n const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);\r\n if (emitter.innerAngle) {\r\n weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);\r\n }\r\n if (emitter.outerAngle) {\r\n weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);\r\n }\r\n if (emitter.volume) {\r\n weightedSound.volume = emitter.volume;\r\n }\r\n emitter._babylonData!.sound = weightedSound;\r\n });\r\n\r\n emitter._babylonData = {\r\n loaded: promise,\r\n };\r\n }\r\n\r\n return emitter._babylonData.loaded;\r\n }\r\n\r\n private _getEventAction(\r\n context: string,\r\n sound: WeightedSound,\r\n action: IMSFTAudioEmitter_AnimationEventAction,\r\n time: number,\r\n startOffset?: number\r\n ): (currentFrame: number) => void {\r\n switch (action) {\r\n case IMSFTAudioEmitter_AnimationEventAction.play: {\r\n return (currentFrame: number) => {\r\n const frameOffset = (startOffset || 0) + (currentFrame - time);\r\n sound.play(frameOffset);\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.stop: {\r\n return () => {\r\n sound.stop();\r\n };\r\n }\r\n case IMSFTAudioEmitter_AnimationEventAction.pause: {\r\n return () => {\r\n sound.pause();\r\n };\r\n }\r\n default: {\r\n throw new Error(`${context}: Unsupported action ${action}`);\r\n }\r\n }\r\n }\r\n\r\n private _loadAnimationEventAsync(\r\n context: string,\r\n animationContext: string,\r\n animation: IAnimation,\r\n event: ILoaderAnimationEvent,\r\n babylonAnimationGroup: AnimationGroup\r\n ): Promise<void> {\r\n if (babylonAnimationGroup.targetedAnimations.length == 0) {\r\n return Promise.resolve();\r\n }\r\n const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];\r\n const emitterIndex = event.emitter;\r\n const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);\r\n return this._loadEmitterAsync(context, emitter).then(() => {\r\n const sound = emitter._babylonData!.sound;\r\n if (sound) {\r\n const babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));\r\n babylonAnimation.animation.addEvent(babylonAnimationEvent);\r\n // Make sure all started audio stops when this animation is terminated.\r\n babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {\r\n sound.stop();\r\n });\r\n babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {\r\n sound.pause();\r\n });\r\n }\r\n });\r\n }\r\n}\r\n\r\nGLTFLoader.RegisterExtension(NAME, (loader) => new MSFT_audio_emitter(loader));\r\n"]}
|