@babylonjs/loaders 5.0.0-rc.1 → 5.0.0-rc.12

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