@babylonjs/loaders 5.0.0-rc.5 → 5.0.0-rc.9

Sign up to get free protection for your applications and to get access to all the features.
Files changed (115) hide show
  1. package/OBJ/index.d.ts +4 -4
  2. package/OBJ/index.js +4 -4
  3. package/OBJ/mtlFileLoader.d.ts +41 -41
  4. package/OBJ/mtlFileLoader.js +232 -232
  5. package/OBJ/objFileLoader.d.ts +126 -126
  6. package/OBJ/objFileLoader.js +296 -296
  7. package/OBJ/objLoadingOptions.d.ts +43 -43
  8. package/OBJ/objLoadingOptions.js +1 -1
  9. package/OBJ/solidParser.d.ts +154 -154
  10. package/OBJ/solidParser.js +693 -693
  11. package/STL/index.d.ts +1 -1
  12. package/STL/index.js +1 -1
  13. package/STL/stlFileLoader.d.ts +64 -64
  14. package/STL/stlFileLoader.js +233 -233
  15. package/glTF/1.0/glTFBinaryExtension.d.ts +13 -13
  16. package/glTF/1.0/glTFBinaryExtension.js +60 -60
  17. package/glTF/1.0/glTFLoader.d.ts +136 -136
  18. package/glTF/1.0/glTFLoader.js +1815 -1815
  19. package/glTF/1.0/glTFLoaderInterfaces.d.ts +412 -412
  20. package/glTF/1.0/glTFLoaderInterfaces.js +95 -95
  21. package/glTF/1.0/glTFLoaderUtils.d.ts +62 -62
  22. package/glTF/1.0/glTFLoaderUtils.js +250 -250
  23. package/glTF/1.0/glTFMaterialsCommonExtension.d.ts +10 -10
  24. package/glTF/1.0/glTFMaterialsCommonExtension.js +129 -129
  25. package/glTF/1.0/index.d.ts +5 -5
  26. package/glTF/1.0/index.js +5 -5
  27. package/glTF/2.0/Extensions/EXT_lights_image_based.d.ts +43 -43
  28. package/glTF/2.0/Extensions/EXT_lights_image_based.js +117 -117
  29. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.d.ts +36 -36
  30. package/glTF/2.0/Extensions/EXT_mesh_gpu_instancing.js +88 -88
  31. package/glTF/2.0/Extensions/EXT_meshopt_compression.d.ts +34 -34
  32. package/glTF/2.0/Extensions/EXT_meshopt_compression.js +49 -49
  33. package/glTF/2.0/Extensions/EXT_texture_webp.d.ts +29 -29
  34. package/glTF/2.0/Extensions/EXT_texture_webp.js +40 -40
  35. package/glTF/2.0/Extensions/ExtrasAsMetadata.d.ts +50 -50
  36. package/glTF/2.0/Extensions/ExtrasAsMetadata.js +73 -73
  37. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.d.ts +39 -39
  38. package/glTF/2.0/Extensions/KHR_draco_mesh_compression.js +112 -112
  39. package/glTF/2.0/Extensions/KHR_lights_punctual.d.ts +36 -36
  40. package/glTF/2.0/Extensions/KHR_lights_punctual.js +89 -89
  41. package/glTF/2.0/Extensions/KHR_materials_clearcoat.d.ts +39 -39
  42. package/glTF/2.0/Extensions/KHR_materials_clearcoat.js +94 -94
  43. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.d.ts +38 -38
  44. package/glTF/2.0/Extensions/KHR_materials_emissive_strength.js +53 -53
  45. package/glTF/2.0/Extensions/KHR_materials_ior.d.ts +42 -42
  46. package/glTF/2.0/Extensions/KHR_materials_ior.js +62 -62
  47. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.d.ts +38 -38
  48. package/glTF/2.0/Extensions/KHR_materials_pbrSpecularGlossiness.js +80 -80
  49. package/glTF/2.0/Extensions/KHR_materials_sheen.d.ts +39 -39
  50. package/glTF/2.0/Extensions/KHR_materials_sheen.js +84 -84
  51. package/glTF/2.0/Extensions/KHR_materials_specular.d.ts +38 -38
  52. package/glTF/2.0/Extensions/KHR_materials_specular.js +74 -74
  53. package/glTF/2.0/Extensions/KHR_materials_translucency.d.ts +39 -39
  54. package/glTF/2.0/Extensions/KHR_materials_translucency.js +83 -83
  55. package/glTF/2.0/Extensions/KHR_materials_transmission.d.ts +38 -38
  56. package/glTF/2.0/Extensions/KHR_materials_transmission.js +288 -288
  57. package/glTF/2.0/Extensions/KHR_materials_unlit.d.ts +38 -38
  58. package/glTF/2.0/Extensions/KHR_materials_unlit.js +73 -73
  59. package/glTF/2.0/Extensions/KHR_materials_variants.d.ts +87 -87
  60. package/glTF/2.0/Extensions/KHR_materials_variants.js +254 -254
  61. package/glTF/2.0/Extensions/KHR_materials_volume.d.ts +39 -39
  62. package/glTF/2.0/Extensions/KHR_materials_volume.js +85 -85
  63. package/glTF/2.0/Extensions/KHR_mesh_quantization.d.ts +22 -22
  64. package/glTF/2.0/Extensions/KHR_mesh_quantization.js +23 -23
  65. package/glTF/2.0/Extensions/KHR_texture_basisu.d.ts +29 -29
  66. package/glTF/2.0/Extensions/KHR_texture_basisu.js +40 -40
  67. package/glTF/2.0/Extensions/KHR_texture_transform.d.ts +33 -33
  68. package/glTF/2.0/Extensions/KHR_texture_transform.js +61 -61
  69. package/glTF/2.0/Extensions/KHR_xmp_json_ld.d.ts +32 -32
  70. package/glTF/2.0/Extensions/KHR_xmp_json_ld.js +49 -49
  71. package/glTF/2.0/Extensions/MSFT_audio_emitter.d.ts +54 -54
  72. package/glTF/2.0/Extensions/MSFT_audio_emitter.js +240 -240
  73. package/glTF/2.0/Extensions/MSFT_lod.d.ts +109 -109
  74. package/glTF/2.0/Extensions/MSFT_lod.js +369 -369
  75. package/glTF/2.0/Extensions/MSFT_minecraftMesh.d.ts +14 -14
  76. package/glTF/2.0/Extensions/MSFT_minecraftMesh.js +36 -36
  77. package/glTF/2.0/Extensions/MSFT_sRGBFactors.d.ts +14 -14
  78. package/glTF/2.0/Extensions/MSFT_sRGBFactors.js +36 -36
  79. package/glTF/2.0/Extensions/index.d.ts +26 -26
  80. package/glTF/2.0/Extensions/index.js +26 -26
  81. package/glTF/2.0/glTFLoader.d.ts +405 -405
  82. package/glTF/2.0/glTFLoader.js +2366 -2366
  83. package/glTF/2.0/glTFLoaderExtension.d.ts +152 -152
  84. package/glTF/2.0/glTFLoaderExtension.js +1 -1
  85. package/glTF/2.0/glTFLoaderInterfaces.d.ts +211 -211
  86. package/glTF/2.0/glTFLoaderInterfaces.js +1 -1
  87. package/glTF/2.0/index.d.ts +4 -4
  88. package/glTF/2.0/index.js +4 -4
  89. package/glTF/glTFFileLoader.d.ts +433 -433
  90. package/glTF/glTFFileLoader.js +927 -927
  91. package/glTF/glTFValidation.d.ts +29 -29
  92. package/glTF/glTFValidation.js +123 -123
  93. package/glTF/index.d.ts +5 -5
  94. package/glTF/index.js +5 -5
  95. package/index.d.ts +3 -3
  96. package/index.js +3 -3
  97. package/legacy/legacy-glTF.d.ts +2 -2
  98. package/legacy/legacy-glTF.js +18 -18
  99. package/legacy/legacy-glTF1.d.ts +2 -2
  100. package/legacy/legacy-glTF1.js +14 -14
  101. package/legacy/legacy-glTF1FileLoader.d.ts +2 -2
  102. package/legacy/legacy-glTF1FileLoader.js +3 -3
  103. package/legacy/legacy-glTF2.d.ts +2 -2
  104. package/legacy/legacy-glTF2.js +32 -32
  105. package/legacy/legacy-glTF2FileLoader.d.ts +2 -2
  106. package/legacy/legacy-glTF2FileLoader.js +3 -3
  107. package/legacy/legacy-glTFFileLoader.d.ts +3 -3
  108. package/legacy/legacy-glTFFileLoader.js +4 -4
  109. package/legacy/legacy-objFileLoader.d.ts +1 -1
  110. package/legacy/legacy-objFileLoader.js +12 -12
  111. package/legacy/legacy-stlFileLoader.d.ts +1 -1
  112. package/legacy/legacy-stlFileLoader.js +12 -12
  113. package/legacy/legacy.d.ts +6 -6
  114. package/legacy/legacy.js +7 -7
  115. package/package.json +3 -3
@@ -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";
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