@babylonjs/viewer 7.23.1-alpha → 7.23.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (522) hide show
  1. package/configuration/configuration.d.ts +107 -0
  2. package/configuration/configuration.js +16 -0
  3. package/configuration/configuration.js.map +1 -0
  4. package/configuration/configurationCompatibility.d.ts +8 -0
  5. package/configuration/configurationCompatibility.js +66 -0
  6. package/configuration/configurationCompatibility.js.map +1 -0
  7. package/configuration/configurationContainer.d.ts +10 -0
  8. package/configuration/configurationContainer.js +10 -0
  9. package/configuration/configurationContainer.js.map +1 -0
  10. package/configuration/globals.d.ts +6 -0
  11. package/configuration/globals.js +18 -0
  12. package/configuration/globals.js.map +1 -0
  13. package/configuration/index.d.ts +2 -0
  14. package/configuration/index.js +4 -0
  15. package/configuration/index.js.map +1 -0
  16. package/configuration/interfaces/cameraConfiguration.d.ts +31 -0
  17. package/configuration/interfaces/cameraConfiguration.js +2 -0
  18. package/configuration/interfaces/cameraConfiguration.js.map +1 -0
  19. package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -0
  20. package/configuration/interfaces/colorGradingConfiguration.js +2 -0
  21. package/configuration/interfaces/colorGradingConfiguration.js.map +1 -0
  22. package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -0
  23. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +2 -0
  24. package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +1 -0
  25. package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -0
  26. package/configuration/interfaces/environmentMapConfiguration.js +2 -0
  27. package/configuration/interfaces/environmentMapConfiguration.js.map +1 -0
  28. package/configuration/interfaces/groundConfiguration.d.ts +24 -0
  29. package/configuration/interfaces/groundConfiguration.js +2 -0
  30. package/configuration/interfaces/groundConfiguration.js.map +1 -0
  31. package/configuration/interfaces/imageProcessingConfiguration.d.ts +45 -0
  32. package/configuration/interfaces/imageProcessingConfiguration.js +2 -0
  33. package/configuration/interfaces/imageProcessingConfiguration.js.map +1 -0
  34. package/configuration/interfaces/index.d.ts +15 -0
  35. package/configuration/interfaces/index.js +16 -0
  36. package/configuration/interfaces/index.js.map +1 -0
  37. package/configuration/interfaces/lightConfiguration.d.ts +60 -0
  38. package/configuration/interfaces/lightConfiguration.js +2 -0
  39. package/configuration/interfaces/lightConfiguration.js.map +1 -0
  40. package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -0
  41. package/configuration/interfaces/modelAnimationConfiguration.js +2 -0
  42. package/configuration/interfaces/modelAnimationConfiguration.js.map +1 -0
  43. package/configuration/interfaces/modelConfiguration.d.ts +65 -0
  44. package/configuration/interfaces/modelConfiguration.js +2 -0
  45. package/configuration/interfaces/modelConfiguration.js.map +1 -0
  46. package/configuration/interfaces/observersConfiguration.d.ts +5 -0
  47. package/configuration/interfaces/observersConfiguration.js +2 -0
  48. package/configuration/interfaces/observersConfiguration.js.map +1 -0
  49. package/configuration/interfaces/sceneConfiguration.d.ts +48 -0
  50. package/configuration/interfaces/sceneConfiguration.js +2 -0
  51. package/configuration/interfaces/sceneConfiguration.js.map +1 -0
  52. package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -0
  53. package/configuration/interfaces/sceneOptimizerConfiguration.js +2 -0
  54. package/configuration/interfaces/sceneOptimizerConfiguration.js.map +1 -0
  55. package/configuration/interfaces/skyboxConfiguration.d.ts +21 -0
  56. package/configuration/interfaces/skyboxConfiguration.js +2 -0
  57. package/configuration/interfaces/skyboxConfiguration.js.map +1 -0
  58. package/configuration/interfaces/templateConfiguration.d.ts +67 -0
  59. package/configuration/interfaces/templateConfiguration.js +2 -0
  60. package/configuration/interfaces/templateConfiguration.js.map +1 -0
  61. package/configuration/interfaces/vrConfiguration.d.ts +16 -0
  62. package/configuration/interfaces/vrConfiguration.js +2 -0
  63. package/configuration/interfaces/vrConfiguration.js.map +1 -0
  64. package/configuration/loader.d.ts +4 -0
  65. package/configuration/loader.js +17 -0
  66. package/configuration/loader.js.map +1 -0
  67. package/configuration/mappers.d.ts +43 -0
  68. package/configuration/mappers.js +192 -0
  69. package/configuration/mappers.js.map +1 -0
  70. package/configuration/renderOnlyLoader.d.ts +33 -0
  71. package/configuration/renderOnlyLoader.js +162 -0
  72. package/configuration/renderOnlyLoader.js.map +1 -0
  73. package/configuration/types/default.d.ts +6 -0
  74. package/configuration/types/default.js +121 -0
  75. package/configuration/types/default.js.map +1 -0
  76. package/configuration/types/environmentMap.d.ts +5 -0
  77. package/configuration/types/environmentMap.js +14 -0
  78. package/configuration/types/environmentMap.js.map +1 -0
  79. package/configuration/types/extended.d.ts +6 -0
  80. package/configuration/types/extended.js +317 -0
  81. package/configuration/types/extended.js.map +1 -0
  82. package/configuration/types/index.d.ts +14 -0
  83. package/configuration/types/index.js +51 -0
  84. package/configuration/types/index.js.map +1 -0
  85. package/configuration/types/minimal.d.ts +6 -0
  86. package/configuration/types/minimal.js +43 -0
  87. package/configuration/types/minimal.js.map +1 -0
  88. package/configuration/types/renderOnlyDefault.d.ts +30 -0
  89. package/configuration/types/renderOnlyDefault.js +31 -0
  90. package/configuration/types/renderOnlyDefault.js.map +1 -0
  91. package/configuration/types/shadowLight.d.ts +9 -0
  92. package/configuration/types/shadowLight.js +64 -0
  93. package/configuration/types/shadowLight.js.map +1 -0
  94. package/helper/index.d.ts +29 -0
  95. package/helper/index.js +66 -0
  96. package/helper/index.js.map +1 -0
  97. package/index.d.ts +30 -0
  98. package/index.js +46 -0
  99. package/index.js.map +1 -0
  100. package/initializer.d.ts +11 -0
  101. package/initializer.js +35 -0
  102. package/initializer.js.map +1 -0
  103. package/interfaces.d.ts +5 -0
  104. package/interfaces.js +7 -0
  105. package/interfaces.js.map +1 -0
  106. package/labs/environmentSerializer.d.ts +126 -0
  107. package/labs/environmentSerializer.js +191 -0
  108. package/labs/environmentSerializer.js.map +1 -0
  109. package/labs/texture.d.ts +183 -0
  110. package/labs/texture.js +351 -0
  111. package/labs/texture.js.map +1 -0
  112. package/labs/viewerLabs.d.ts +51 -0
  113. package/labs/viewerLabs.js +134 -0
  114. package/labs/viewerLabs.js.map +1 -0
  115. package/loader/modelLoader.d.ts +56 -0
  116. package/loader/modelLoader.js +199 -0
  117. package/loader/modelLoader.js.map +1 -0
  118. package/loader/plugins/applyMaterialConfig.d.ts +12 -0
  119. package/loader/plugins/applyMaterialConfig.js +16 -0
  120. package/loader/plugins/applyMaterialConfig.js.map +1 -0
  121. package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -0
  122. package/loader/plugins/extendedMaterialLoaderPlugin.js +16 -0
  123. package/loader/plugins/extendedMaterialLoaderPlugin.js.map +1 -0
  124. package/loader/plugins/index.d.ts +19 -0
  125. package/loader/plugins/index.js +44 -0
  126. package/loader/plugins/index.js.map +1 -0
  127. package/loader/plugins/loaderPlugin.d.ts +24 -0
  128. package/loader/plugins/loaderPlugin.js +2 -0
  129. package/loader/plugins/loaderPlugin.js.map +1 -0
  130. package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -0
  131. package/loader/plugins/msftLodLoaderPlugin.js +21 -0
  132. package/loader/plugins/msftLodLoaderPlugin.js.map +1 -0
  133. package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -0
  134. package/loader/plugins/telemetryLoaderPlugin.js +36 -0
  135. package/loader/plugins/telemetryLoaderPlugin.js.map +1 -0
  136. package/managers/observablesManager.d.ts +66 -0
  137. package/managers/observablesManager.js +35 -0
  138. package/managers/observablesManager.js.map +1 -0
  139. package/managers/sceneManager.d.ts +245 -0
  140. package/managers/sceneManager.js +1375 -0
  141. package/managers/sceneManager.js.map +1 -0
  142. package/managers/telemetryManager.d.ts +78 -0
  143. package/managers/telemetryManager.js +117 -0
  144. package/managers/telemetryManager.js.map +1 -0
  145. package/model/modelAnimation.d.ts +215 -0
  146. package/model/modelAnimation.js +237 -0
  147. package/model/modelAnimation.js.map +1 -0
  148. package/model/viewerModel.d.ts +233 -0
  149. package/model/viewerModel.js +673 -0
  150. package/model/viewerModel.js.map +1 -0
  151. package/optimizer/custom/extended.d.ts +13 -0
  152. package/optimizer/custom/extended.js +101 -0
  153. package/optimizer/custom/extended.js.map +1 -0
  154. package/optimizer/custom/index.d.ts +9 -0
  155. package/optimizer/custom/index.js +26 -0
  156. package/optimizer/custom/index.js.map +1 -0
  157. package/package.json +27 -17
  158. package/readme.md +21 -35
  159. package/renderOnlyIndex.d.ts +11 -0
  160. package/renderOnlyIndex.js +18 -0
  161. package/renderOnlyIndex.js.map +1 -0
  162. package/templating/eventManager.d.ts +35 -0
  163. package/templating/eventManager.js +66 -0
  164. package/templating/eventManager.js.map +1 -0
  165. package/templating/plugins/hdButtonPlugin.d.ts +9 -0
  166. package/templating/plugins/hdButtonPlugin.js +21 -0
  167. package/templating/plugins/hdButtonPlugin.js.map +1 -0
  168. package/templating/plugins/printButton.d.ts +9 -0
  169. package/templating/plugins/printButton.js +40 -0
  170. package/templating/plugins/printButton.js.map +1 -0
  171. package/templating/templateManager.d.ts +197 -0
  172. package/templating/templateManager.js +561 -0
  173. package/templating/templateManager.js.map +1 -0
  174. package/templating/viewerTemplatePlugin.d.ts +21 -0
  175. package/templating/viewerTemplatePlugin.js +69 -0
  176. package/templating/viewerTemplatePlugin.js.map +1 -0
  177. package/viewer/defaultViewer.d.ts +130 -0
  178. package/viewer/defaultViewer.js +675 -0
  179. package/viewer/defaultViewer.js.map +1 -0
  180. package/viewer/renderOnlyViewer.d.ts +9 -0
  181. package/viewer/renderOnlyViewer.js +46 -0
  182. package/viewer/renderOnlyViewer.js.map +1 -0
  183. package/viewer/viewer.d.ts +258 -0
  184. package/viewer/viewer.js +783 -0
  185. package/viewer/viewer.js.map +1 -0
  186. package/viewer/viewerManager.d.ts +58 -0
  187. package/viewer/viewerManager.js +91 -0
  188. package/viewer/viewerManager.js.map +1 -0
  189. package/viewer/viewerWithTemplate.d.ts +9 -0
  190. package/viewer/viewerWithTemplate.js +20 -0
  191. package/viewer/viewerWithTemplate.js.map +1 -0
  192. package/dist/babylon-viewer.esm.js +0 -2
  193. package/dist/babylon-viewer.esm.js.map +0 -1
  194. package/dist/babylon-viewer.esm.min.js +0 -2
  195. package/dist/babylon-viewer.esm.min.js.map +0 -1
  196. package/dist/chunks/EXT_lights_image_based-D3ZBYLgC.esm.js +0 -170
  197. package/dist/chunks/EXT_lights_image_based-D3ZBYLgC.esm.js.map +0 -1
  198. package/dist/chunks/EXT_lights_image_based-DyWZGFdC.esm.min.js +0 -2
  199. package/dist/chunks/EXT_lights_image_based-DyWZGFdC.esm.min.js.map +0 -1
  200. package/dist/chunks/EXT_mesh_gpu_instancing-BsSuxC3A.esm.js +0 -86
  201. package/dist/chunks/EXT_mesh_gpu_instancing-BsSuxC3A.esm.js.map +0 -1
  202. package/dist/chunks/EXT_mesh_gpu_instancing-DtTWXKzv.esm.min.js +0 -2
  203. package/dist/chunks/EXT_mesh_gpu_instancing-DtTWXKzv.esm.min.js.map +0 -1
  204. package/dist/chunks/EXT_meshopt_compression-BncKn2rD.esm.js +0 -134
  205. package/dist/chunks/EXT_meshopt_compression-BncKn2rD.esm.js.map +0 -1
  206. package/dist/chunks/EXT_meshopt_compression-CjW8GcrA.esm.min.js +0 -2
  207. package/dist/chunks/EXT_meshopt_compression-CjW8GcrA.esm.min.js.map +0 -1
  208. package/dist/chunks/EXT_texture_avif-DLrVqqUz.esm.min.js +0 -2
  209. package/dist/chunks/EXT_texture_avif-DLrVqqUz.esm.min.js.map +0 -1
  210. package/dist/chunks/EXT_texture_avif-wG4GNQfZ.esm.js +0 -44
  211. package/dist/chunks/EXT_texture_avif-wG4GNQfZ.esm.js.map +0 -1
  212. package/dist/chunks/EXT_texture_webp-BccV6Svg.esm.js +0 -43
  213. package/dist/chunks/EXT_texture_webp-BccV6Svg.esm.js.map +0 -1
  214. package/dist/chunks/EXT_texture_webp-DNAe2ii8.esm.min.js +0 -2
  215. package/dist/chunks/EXT_texture_webp-DNAe2ii8.esm.min.js.map +0 -1
  216. package/dist/chunks/ExtrasAsMetadata-BA0NyQBn.esm.js +0 -64
  217. package/dist/chunks/ExtrasAsMetadata-BA0NyQBn.esm.js.map +0 -1
  218. package/dist/chunks/ExtrasAsMetadata-BN02lRw7.esm.min.js +0 -2
  219. package/dist/chunks/ExtrasAsMetadata-BN02lRw7.esm.min.js.map +0 -1
  220. package/dist/chunks/KHR_animation_pointer-B7mk-XJN.esm.min.js +0 -2
  221. package/dist/chunks/KHR_animation_pointer-B7mk-XJN.esm.min.js.map +0 -1
  222. package/dist/chunks/KHR_animation_pointer-BFFpQV4X.esm.js +0 -343
  223. package/dist/chunks/KHR_animation_pointer-BFFpQV4X.esm.js.map +0 -1
  224. package/dist/chunks/KHR_draco_mesh_compression-7zqRIpZt.esm.js +0 -610
  225. package/dist/chunks/KHR_draco_mesh_compression-7zqRIpZt.esm.js.map +0 -1
  226. package/dist/chunks/KHR_draco_mesh_compression-Bw4rV4ln.esm.min.js +0 -2
  227. package/dist/chunks/KHR_draco_mesh_compression-Bw4rV4ln.esm.min.js.map +0 -1
  228. package/dist/chunks/KHR_interactivity-Bd_6hpGb.esm.js +0 -4033
  229. package/dist/chunks/KHR_interactivity-Bd_6hpGb.esm.js.map +0 -1
  230. package/dist/chunks/KHR_interactivity-DIJyLERv.esm.min.js +0 -2
  231. package/dist/chunks/KHR_interactivity-DIJyLERv.esm.min.js.map +0 -1
  232. package/dist/chunks/KHR_lights_punctual-CFUUYlNK.esm.min.js +0 -2
  233. package/dist/chunks/KHR_lights_punctual-CFUUYlNK.esm.min.js.map +0 -1
  234. package/dist/chunks/KHR_lights_punctual-XL2dnY2h.esm.js +0 -1253
  235. package/dist/chunks/KHR_lights_punctual-XL2dnY2h.esm.js.map +0 -1
  236. package/dist/chunks/KHR_materials_anisotropy-04SftzV0.esm.min.js +0 -2
  237. package/dist/chunks/KHR_materials_anisotropy-04SftzV0.esm.min.js.map +0 -1
  238. package/dist/chunks/KHR_materials_anisotropy-gAd08wDG.esm.js +0 -64
  239. package/dist/chunks/KHR_materials_anisotropy-gAd08wDG.esm.js.map +0 -1
  240. package/dist/chunks/KHR_materials_clearcoat-9GQaVx6k.esm.min.js +0 -2
  241. package/dist/chunks/KHR_materials_clearcoat-9GQaVx6k.esm.min.js.map +0 -1
  242. package/dist/chunks/KHR_materials_clearcoat-Cv_yIIaW.esm.js +0 -96
  243. package/dist/chunks/KHR_materials_clearcoat-Cv_yIIaW.esm.js.map +0 -1
  244. package/dist/chunks/KHR_materials_diffuse_transmission-Dj9EU7q2.esm.js +0 -96
  245. package/dist/chunks/KHR_materials_diffuse_transmission-Dj9EU7q2.esm.js.map +0 -1
  246. package/dist/chunks/KHR_materials_diffuse_transmission-fmv70uuH.esm.min.js +0 -2
  247. package/dist/chunks/KHR_materials_diffuse_transmission-fmv70uuH.esm.min.js.map +0 -1
  248. package/dist/chunks/KHR_materials_dispersion-CCzM2Avp.esm.min.js +0 -2
  249. package/dist/chunks/KHR_materials_dispersion-CCzM2Avp.esm.min.js.map +0 -1
  250. package/dist/chunks/KHR_materials_dispersion-JNxGdAqc.esm.js +0 -63
  251. package/dist/chunks/KHR_materials_dispersion-JNxGdAqc.esm.js.map +0 -1
  252. package/dist/chunks/KHR_materials_emissive_strength-D25-ItKl.esm.min.js +0 -2
  253. package/dist/chunks/KHR_materials_emissive_strength-D25-ItKl.esm.min.js.map +0 -1
  254. package/dist/chunks/KHR_materials_emissive_strength-DlkptyaM.esm.js +0 -55
  255. package/dist/chunks/KHR_materials_emissive_strength-DlkptyaM.esm.js.map +0 -1
  256. package/dist/chunks/KHR_materials_ior-Jqj5Ph_V.esm.min.js +0 -2
  257. package/dist/chunks/KHR_materials_ior-Jqj5Ph_V.esm.min.js.map +0 -1
  258. package/dist/chunks/KHR_materials_ior-KGZBae4Y.esm.js +0 -64
  259. package/dist/chunks/KHR_materials_ior-KGZBae4Y.esm.js.map +0 -1
  260. package/dist/chunks/KHR_materials_iridescence-ByOHUtdO.esm.min.js +0 -2
  261. package/dist/chunks/KHR_materials_iridescence-ByOHUtdO.esm.min.js.map +0 -1
  262. package/dist/chunks/KHR_materials_iridescence-FmAV1QDy.esm.js +0 -72
  263. package/dist/chunks/KHR_materials_iridescence-FmAV1QDy.esm.js.map +0 -1
  264. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-BiqCrcmj.esm.min.js +0 -2
  265. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-BiqCrcmj.esm.min.js.map +0 -1
  266. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-CRnlTYx-.esm.js +0 -81
  267. package/dist/chunks/KHR_materials_pbrSpecularGlossiness-CRnlTYx-.esm.js.map +0 -1
  268. package/dist/chunks/KHR_materials_sheen-7li6Dlkh.esm.js +0 -85
  269. package/dist/chunks/KHR_materials_sheen-7li6Dlkh.esm.js.map +0 -1
  270. package/dist/chunks/KHR_materials_sheen-BL2qM8Rp.esm.min.js +0 -2
  271. package/dist/chunks/KHR_materials_sheen-BL2qM8Rp.esm.min.js.map +0 -1
  272. package/dist/chunks/KHR_materials_specular-C2ks7gPC.esm.js +0 -75
  273. package/dist/chunks/KHR_materials_specular-C2ks7gPC.esm.js.map +0 -1
  274. package/dist/chunks/KHR_materials_specular-DCAt3T_l.esm.min.js +0 -2
  275. package/dist/chunks/KHR_materials_specular-DCAt3T_l.esm.min.js.map +0 -1
  276. package/dist/chunks/KHR_materials_transmission-B8w41MT6.esm.min.js +0 -2
  277. package/dist/chunks/KHR_materials_transmission-B8w41MT6.esm.min.js.map +0 -1
  278. package/dist/chunks/KHR_materials_transmission-DRL9BE9q.esm.js +0 -307
  279. package/dist/chunks/KHR_materials_transmission-DRL9BE9q.esm.js.map +0 -1
  280. package/dist/chunks/KHR_materials_unlit-B-il-TRX.esm.min.js +0 -2
  281. package/dist/chunks/KHR_materials_unlit-B-il-TRX.esm.min.js.map +0 -1
  282. package/dist/chunks/KHR_materials_unlit-B44Oqon6.esm.js +0 -74
  283. package/dist/chunks/KHR_materials_unlit-B44Oqon6.esm.js.map +0 -1
  284. package/dist/chunks/KHR_materials_variants-BCdEgpch.esm.js +0 -238
  285. package/dist/chunks/KHR_materials_variants-BCdEgpch.esm.js.map +0 -1
  286. package/dist/chunks/KHR_materials_variants-ClQElTeo.esm.min.js +0 -2
  287. package/dist/chunks/KHR_materials_variants-ClQElTeo.esm.min.js.map +0 -1
  288. package/dist/chunks/KHR_materials_volume-BXv3M95S.esm.min.js +0 -2
  289. package/dist/chunks/KHR_materials_volume-BXv3M95S.esm.min.js.map +0 -1
  290. package/dist/chunks/KHR_materials_volume-BuUrRniE.esm.js +0 -88
  291. package/dist/chunks/KHR_materials_volume-BuUrRniE.esm.js.map +0 -1
  292. package/dist/chunks/KHR_mesh_quantization-WPngIGGs.esm.min.js +0 -2
  293. package/dist/chunks/KHR_mesh_quantization-WPngIGGs.esm.min.js.map +0 -1
  294. package/dist/chunks/KHR_mesh_quantization-p2nyy6Ym.esm.js +0 -26
  295. package/dist/chunks/KHR_mesh_quantization-p2nyy6Ym.esm.js.map +0 -1
  296. package/dist/chunks/KHR_texture_basisu-BHsmOUDV.esm.js +0 -43
  297. package/dist/chunks/KHR_texture_basisu-BHsmOUDV.esm.js.map +0 -1
  298. package/dist/chunks/KHR_texture_basisu-DObdWvzE.esm.min.js +0 -2
  299. package/dist/chunks/KHR_texture_basisu-DObdWvzE.esm.min.js.map +0 -1
  300. package/dist/chunks/KHR_texture_transform-B7NCdTO_.esm.js +0 -63
  301. package/dist/chunks/KHR_texture_transform-B7NCdTO_.esm.js.map +0 -1
  302. package/dist/chunks/KHR_texture_transform-D6Ee6UiP.esm.min.js +0 -2
  303. package/dist/chunks/KHR_texture_transform-D6Ee6UiP.esm.min.js.map +0 -1
  304. package/dist/chunks/KHR_xmp_json_ld-Coh_hfCi.esm.js +0 -51
  305. package/dist/chunks/KHR_xmp_json_ld-Coh_hfCi.esm.js.map +0 -1
  306. package/dist/chunks/KHR_xmp_json_ld-ijOY8DMb.esm.min.js +0 -2
  307. package/dist/chunks/KHR_xmp_json_ld-ijOY8DMb.esm.min.js.map +0 -1
  308. package/dist/chunks/MSFT_audio_emitter-CGjUSgI2.esm.min.js +0 -2
  309. package/dist/chunks/MSFT_audio_emitter-CGjUSgI2.esm.min.js.map +0 -1
  310. package/dist/chunks/MSFT_audio_emitter-fFvTv2YK.esm.js +0 -1600
  311. package/dist/chunks/MSFT_audio_emitter-fFvTv2YK.esm.js.map +0 -1
  312. package/dist/chunks/MSFT_lod-Bql1icOF.esm.js +0 -337
  313. package/dist/chunks/MSFT_lod-Bql1icOF.esm.js.map +0 -1
  314. package/dist/chunks/MSFT_lod-Du_akN0I.esm.min.js +0 -2
  315. package/dist/chunks/MSFT_lod-Du_akN0I.esm.min.js.map +0 -1
  316. package/dist/chunks/MSFT_minecraftMesh-Brch3HUo.esm.min.js +0 -2
  317. package/dist/chunks/MSFT_minecraftMesh-Brch3HUo.esm.min.js.map +0 -1
  318. package/dist/chunks/MSFT_minecraftMesh-jrYC8YE9.esm.js +0 -46
  319. package/dist/chunks/MSFT_minecraftMesh-jrYC8YE9.esm.js.map +0 -1
  320. package/dist/chunks/MSFT_sRGBFactors-Dp3CtJ9B.esm.js +0 -47
  321. package/dist/chunks/MSFT_sRGBFactors-Dp3CtJ9B.esm.js.map +0 -1
  322. package/dist/chunks/MSFT_sRGBFactors-LZM-HF4P.esm.min.js +0 -2
  323. package/dist/chunks/MSFT_sRGBFactors-LZM-HF4P.esm.min.js.map +0 -1
  324. package/dist/chunks/assetContainer-Bo08Fxv3.esm.min.js +0 -2
  325. package/dist/chunks/assetContainer-Bo08Fxv3.esm.min.js.map +0 -1
  326. package/dist/chunks/assetContainer-DVOdWL9b.esm.js +0 -1598
  327. package/dist/chunks/assetContainer-DVOdWL9b.esm.js.map +0 -1
  328. package/dist/chunks/basisTextureLoader-C2Or-Jx_.esm.min.js +0 -2
  329. package/dist/chunks/basisTextureLoader-C2Or-Jx_.esm.min.js.map +0 -1
  330. package/dist/chunks/basisTextureLoader-DiYg6uNN.esm.js +0 -600
  331. package/dist/chunks/basisTextureLoader-DiYg6uNN.esm.js.map +0 -1
  332. package/dist/chunks/ddsTextureLoader-CDlttCBi.esm.js +0 -87
  333. package/dist/chunks/ddsTextureLoader-CDlttCBi.esm.js.map +0 -1
  334. package/dist/chunks/ddsTextureLoader-T_I1TPiz.esm.min.js +0 -2
  335. package/dist/chunks/ddsTextureLoader-T_I1TPiz.esm.min.js.map +0 -1
  336. package/dist/chunks/default.fragment-C8ZCxgTK.esm.js +0 -515
  337. package/dist/chunks/default.fragment-C8ZCxgTK.esm.js.map +0 -1
  338. package/dist/chunks/default.fragment-Conpp30r.esm.js +0 -452
  339. package/dist/chunks/default.fragment-Conpp30r.esm.js.map +0 -1
  340. package/dist/chunks/default.fragment-DTP98j1l.esm.min.js +0 -2
  341. package/dist/chunks/default.fragment-DTP98j1l.esm.min.js.map +0 -1
  342. package/dist/chunks/default.fragment-DjistPBR.esm.min.js +0 -2
  343. package/dist/chunks/default.fragment-DjistPBR.esm.min.js.map +0 -1
  344. package/dist/chunks/default.vertex-BSCjzhXG.esm.js +0 -178
  345. package/dist/chunks/default.vertex-BSCjzhXG.esm.js.map +0 -1
  346. package/dist/chunks/default.vertex-Ba7zxY0T.esm.min.js +0 -2
  347. package/dist/chunks/default.vertex-Ba7zxY0T.esm.min.js.map +0 -1
  348. package/dist/chunks/default.vertex-CPurFhOJ.esm.js +0 -199
  349. package/dist/chunks/default.vertex-CPurFhOJ.esm.js.map +0 -1
  350. package/dist/chunks/default.vertex-D_4jDtBx.esm.min.js +0 -2
  351. package/dist/chunks/default.vertex-D_4jDtBx.esm.min.js.map +0 -1
  352. package/dist/chunks/defaultUboDeclaration-BjT2yBnm.esm.js +0 -15
  353. package/dist/chunks/defaultUboDeclaration-BjT2yBnm.esm.js.map +0 -1
  354. package/dist/chunks/defaultUboDeclaration-BuAk9gJA.esm.min.js +0 -2
  355. package/dist/chunks/defaultUboDeclaration-BuAk9gJA.esm.min.js.map +0 -1
  356. package/dist/chunks/defaultUboDeclaration-CC8YfLoS.esm.min.js +0 -2
  357. package/dist/chunks/defaultUboDeclaration-CC8YfLoS.esm.min.js.map +0 -1
  358. package/dist/chunks/defaultUboDeclaration-ClvuiT6M.esm.js +0 -13
  359. package/dist/chunks/defaultUboDeclaration-ClvuiT6M.esm.js.map +0 -1
  360. package/dist/chunks/envTextureLoader-DuE-52NK.esm.min.js +0 -2
  361. package/dist/chunks/envTextureLoader-DuE-52NK.esm.min.js.map +0 -1
  362. package/dist/chunks/envTextureLoader-ENMUumOz.esm.js +0 -63
  363. package/dist/chunks/envTextureLoader-ENMUumOz.esm.js.map +0 -1
  364. package/dist/chunks/environmentTextureTools-Cw-ZbYYv.esm.js +0 -381
  365. package/dist/chunks/environmentTextureTools-Cw-ZbYYv.esm.js.map +0 -1
  366. package/dist/chunks/environmentTextureTools-mWXMV1Cr.esm.min.js +0 -2
  367. package/dist/chunks/environmentTextureTools-mWXMV1Cr.esm.min.js.map +0 -1
  368. package/dist/chunks/exrTextureLoader-9ioAK1Ph.esm.js +0 -1682
  369. package/dist/chunks/exrTextureLoader-9ioAK1Ph.esm.js.map +0 -1
  370. package/dist/chunks/exrTextureLoader-zc2N62c3.esm.min.js +0 -2
  371. package/dist/chunks/exrTextureLoader-zc2N62c3.esm.min.js.map +0 -1
  372. package/dist/chunks/fogFragment-DLguActo.esm.min.js +0 -2
  373. package/dist/chunks/fogFragment-DLguActo.esm.min.js.map +0 -1
  374. package/dist/chunks/fogFragment-sACeXatv.esm.js +0 -102
  375. package/dist/chunks/fogFragment-sACeXatv.esm.js.map +0 -1
  376. package/dist/chunks/glTFLoader-BuxqXvJ-.esm.min.js +0 -2
  377. package/dist/chunks/glTFLoader-BuxqXvJ-.esm.min.js.map +0 -1
  378. package/dist/chunks/glTFLoader-DB7AOurF.esm.js +0 -7552
  379. package/dist/chunks/glTFLoader-DB7AOurF.esm.js.map +0 -1
  380. package/dist/chunks/glTFLoaderAnimation-BWhMcDgk.esm.min.js +0 -2
  381. package/dist/chunks/glTFLoaderAnimation-BWhMcDgk.esm.min.js.map +0 -1
  382. package/dist/chunks/glTFLoaderAnimation-DK5fvCTY.esm.js +0 -77
  383. package/dist/chunks/glTFLoaderAnimation-DK5fvCTY.esm.js.map +0 -1
  384. package/dist/chunks/gltfPathToObjectConverter-Dyt_Y9jE.esm.min.js +0 -2
  385. package/dist/chunks/gltfPathToObjectConverter-Dyt_Y9jE.esm.min.js.map +0 -1
  386. package/dist/chunks/gltfPathToObjectConverter-GcUmfOyo.esm.js +0 -67
  387. package/dist/chunks/gltfPathToObjectConverter-GcUmfOyo.esm.js.map +0 -1
  388. package/dist/chunks/harmonicsFunctions-BMUi3P6Y.esm.js +0 -35
  389. package/dist/chunks/harmonicsFunctions-BMUi3P6Y.esm.js.map +0 -1
  390. package/dist/chunks/harmonicsFunctions-BWj3xZKa.esm.min.js +0 -2
  391. package/dist/chunks/harmonicsFunctions-BWj3xZKa.esm.min.js.map +0 -1
  392. package/dist/chunks/harmonicsFunctions-D9GUclWs.esm.min.js +0 -2
  393. package/dist/chunks/harmonicsFunctions-D9GUclWs.esm.min.js.map +0 -1
  394. package/dist/chunks/harmonicsFunctions-DQngcILt.esm.js +0 -34
  395. package/dist/chunks/harmonicsFunctions-DQngcILt.esm.js.map +0 -1
  396. package/dist/chunks/hdrTextureLoader-3TOTpFyV.esm.min.js +0 -2
  397. package/dist/chunks/hdrTextureLoader-3TOTpFyV.esm.min.js.map +0 -1
  398. package/dist/chunks/hdrTextureLoader-zIHMNTOp.esm.js +0 -252
  399. package/dist/chunks/hdrTextureLoader-zIHMNTOp.esm.js.map +0 -1
  400. package/dist/chunks/helperFunctions-B_yzbgEv.esm.min.js +0 -2
  401. package/dist/chunks/helperFunctions-B_yzbgEv.esm.min.js.map +0 -1
  402. package/dist/chunks/helperFunctions-BjYz-6zr.esm.js +0 -108
  403. package/dist/chunks/helperFunctions-BjYz-6zr.esm.js.map +0 -1
  404. package/dist/chunks/helperFunctions-CXLST6hZ.esm.js +0 -80
  405. package/dist/chunks/helperFunctions-CXLST6hZ.esm.js.map +0 -1
  406. package/dist/chunks/helperFunctions-DTBzTIjJ.esm.min.js +0 -2
  407. package/dist/chunks/helperFunctions-DTBzTIjJ.esm.min.js.map +0 -1
  408. package/dist/chunks/index-CTNAO7X0.esm.js +0 -81630
  409. package/dist/chunks/index-CTNAO7X0.esm.js.map +0 -1
  410. package/dist/chunks/index-DYqHhEAk.esm.min.js +0 -57
  411. package/dist/chunks/index-DYqHhEAk.esm.min.js.map +0 -1
  412. package/dist/chunks/ktxTextureLoader-9AGBpjf1.esm.js +0 -814
  413. package/dist/chunks/ktxTextureLoader-9AGBpjf1.esm.js.map +0 -1
  414. package/dist/chunks/ktxTextureLoader-DbSU4wBV.esm.min.js +0 -2
  415. package/dist/chunks/ktxTextureLoader-DbSU4wBV.esm.min.js.map +0 -1
  416. package/dist/chunks/logDepthDeclaration-BCN89cGc.esm.min.js +0 -2
  417. package/dist/chunks/logDepthDeclaration-BCN89cGc.esm.min.js.map +0 -1
  418. package/dist/chunks/logDepthDeclaration-CZCatKgj.esm.js +0 -42
  419. package/dist/chunks/logDepthDeclaration-CZCatKgj.esm.js.map +0 -1
  420. package/dist/chunks/logDepthDeclaration-_gJVcKC2.esm.js +0 -35
  421. package/dist/chunks/logDepthDeclaration-_gJVcKC2.esm.js.map +0 -1
  422. package/dist/chunks/logDepthDeclaration-cpc5vyCy.esm.min.js +0 -2
  423. package/dist/chunks/logDepthDeclaration-cpc5vyCy.esm.min.js.map +0 -1
  424. package/dist/chunks/logDepthVertex-7sCVTIjr.esm.min.js +0 -2
  425. package/dist/chunks/logDepthVertex-7sCVTIjr.esm.min.js.map +0 -1
  426. package/dist/chunks/logDepthVertex-B09oc-mi.esm.js +0 -77
  427. package/dist/chunks/logDepthVertex-B09oc-mi.esm.js.map +0 -1
  428. package/dist/chunks/logDepthVertex-Bq3-XtSp.esm.min.js +0 -2
  429. package/dist/chunks/logDepthVertex-Bq3-XtSp.esm.min.js.map +0 -1
  430. package/dist/chunks/logDepthVertex-DZoye-59.esm.js +0 -605
  431. package/dist/chunks/logDepthVertex-DZoye-59.esm.js.map +0 -1
  432. package/dist/chunks/mainUVVaryingDeclaration-LHNQQPPQ.esm.js +0 -11
  433. package/dist/chunks/mainUVVaryingDeclaration-LHNQQPPQ.esm.js.map +0 -1
  434. package/dist/chunks/mainUVVaryingDeclaration-wmRFnah8.esm.min.js +0 -2
  435. package/dist/chunks/mainUVVaryingDeclaration-wmRFnah8.esm.min.js.map +0 -1
  436. package/dist/chunks/objFileLoader-BvWwH6aj.esm.js +0 -1280
  437. package/dist/chunks/objFileLoader-BvWwH6aj.esm.js.map +0 -1
  438. package/dist/chunks/objFileLoader-LDP87u1T.esm.min.js +0 -2
  439. package/dist/chunks/objFileLoader-LDP87u1T.esm.min.js.map +0 -1
  440. package/dist/chunks/oitFragment-BAVtrG6V.esm.min.js +0 -2
  441. package/dist/chunks/oitFragment-BAVtrG6V.esm.min.js.map +0 -1
  442. package/dist/chunks/oitFragment-BqzVjWja.esm.js +0 -1210
  443. package/dist/chunks/oitFragment-BqzVjWja.esm.js.map +0 -1
  444. package/dist/chunks/oitFragment-CIelz994.esm.js +0 -1166
  445. package/dist/chunks/oitFragment-CIelz994.esm.js.map +0 -1
  446. package/dist/chunks/oitFragment-P20Uiy73.esm.min.js +0 -2
  447. package/dist/chunks/oitFragment-P20Uiy73.esm.min.js.map +0 -1
  448. package/dist/chunks/pass.fragment-D-67YTNJ.esm.min.js +0 -2
  449. package/dist/chunks/pass.fragment-D-67YTNJ.esm.min.js.map +0 -1
  450. package/dist/chunks/pass.fragment-ke3_LMQY.esm.js +0 -15
  451. package/dist/chunks/pass.fragment-ke3_LMQY.esm.js.map +0 -1
  452. package/dist/chunks/pbr.fragment-3QJykQmh.esm.js +0 -3228
  453. package/dist/chunks/pbr.fragment-3QJykQmh.esm.js.map +0 -1
  454. package/dist/chunks/pbr.fragment-BfhoPEE4.esm.js +0 -3163
  455. package/dist/chunks/pbr.fragment-BfhoPEE4.esm.js.map +0 -1
  456. package/dist/chunks/pbr.fragment-BpCKAJQO.esm.min.js +0 -2
  457. package/dist/chunks/pbr.fragment-BpCKAJQO.esm.min.js.map +0 -1
  458. package/dist/chunks/pbr.fragment-Buc8F3ii.esm.min.js +0 -2
  459. package/dist/chunks/pbr.fragment-Buc8F3ii.esm.min.js.map +0 -1
  460. package/dist/chunks/pbr.vertex-Bwl6238q.esm.min.js +0 -2
  461. package/dist/chunks/pbr.vertex-Bwl6238q.esm.min.js.map +0 -1
  462. package/dist/chunks/pbr.vertex-COtog_7X.esm.js +0 -335
  463. package/dist/chunks/pbr.vertex-COtog_7X.esm.js.map +0 -1
  464. package/dist/chunks/pbr.vertex-CX-ksiMG.esm.min.js +0 -2
  465. package/dist/chunks/pbr.vertex-CX-ksiMG.esm.min.js.map +0 -1
  466. package/dist/chunks/pbr.vertex-WxxbIMZL.esm.js +0 -208
  467. package/dist/chunks/pbr.vertex-WxxbIMZL.esm.js.map +0 -1
  468. package/dist/chunks/postprocess.vertex-6VuephE3.esm.min.js +0 -2
  469. package/dist/chunks/postprocess.vertex-6VuephE3.esm.min.js.map +0 -1
  470. package/dist/chunks/postprocess.vertex-y9rNSbFH.esm.js +0 -20
  471. package/dist/chunks/postprocess.vertex-y9rNSbFH.esm.js.map +0 -1
  472. package/dist/chunks/rawTexture-BjAjz6eU.esm.min.js +0 -2
  473. package/dist/chunks/rawTexture-BjAjz6eU.esm.min.js.map +0 -1
  474. package/dist/chunks/rawTexture-DzCCPFKA.esm.js +0 -562
  475. package/dist/chunks/rawTexture-DzCCPFKA.esm.js.map +0 -1
  476. package/dist/chunks/rgbdDecode.fragment-B2z-Bt71.esm.js +0 -17
  477. package/dist/chunks/rgbdDecode.fragment-B2z-Bt71.esm.js.map +0 -1
  478. package/dist/chunks/rgbdDecode.fragment-CdzoW-6f.esm.min.js +0 -2
  479. package/dist/chunks/rgbdDecode.fragment-CdzoW-6f.esm.min.js.map +0 -1
  480. package/dist/chunks/rgbdDecode.fragment-DrLvcO8Q.esm.js +0 -17
  481. package/dist/chunks/rgbdDecode.fragment-DrLvcO8Q.esm.js.map +0 -1
  482. package/dist/chunks/rgbdDecode.fragment-DuXK_20s.esm.min.js +0 -2
  483. package/dist/chunks/rgbdDecode.fragment-DuXK_20s.esm.min.js.map +0 -1
  484. package/dist/chunks/rgbdEncode.fragment-B8TjBZ9S.esm.js +0 -17
  485. package/dist/chunks/rgbdEncode.fragment-B8TjBZ9S.esm.js.map +0 -1
  486. package/dist/chunks/rgbdEncode.fragment-CGQHcoVr.esm.min.js +0 -2
  487. package/dist/chunks/rgbdEncode.fragment-CGQHcoVr.esm.min.js.map +0 -1
  488. package/dist/chunks/rgbdEncode.fragment-CHPMUGpL.esm.js +0 -17
  489. package/dist/chunks/rgbdEncode.fragment-CHPMUGpL.esm.js.map +0 -1
  490. package/dist/chunks/rgbdEncode.fragment-Ch8KaRMn.esm.min.js +0 -2
  491. package/dist/chunks/rgbdEncode.fragment-Ch8KaRMn.esm.min.js.map +0 -1
  492. package/dist/chunks/splatFileLoader-BOlEs8up.esm.min.js +0 -2
  493. package/dist/chunks/splatFileLoader-BOlEs8up.esm.min.js.map +0 -1
  494. package/dist/chunks/splatFileLoader-bjTdN6CH.esm.js +0 -3137
  495. package/dist/chunks/splatFileLoader-bjTdN6CH.esm.js.map +0 -1
  496. package/dist/chunks/standardMaterial-AtuI8LET.esm.min.js +0 -2
  497. package/dist/chunks/standardMaterial-AtuI8LET.esm.min.js.map +0 -1
  498. package/dist/chunks/standardMaterial-pkPTNFQZ.esm.js +0 -1809
  499. package/dist/chunks/standardMaterial-pkPTNFQZ.esm.js.map +0 -1
  500. package/dist/chunks/stlFileLoader-D_S8zIWi.esm.min.js +0 -2
  501. package/dist/chunks/stlFileLoader-D_S8zIWi.esm.min.js.map +0 -1
  502. package/dist/chunks/stlFileLoader-LAl8UbnA.esm.js +0 -237
  503. package/dist/chunks/stlFileLoader-LAl8UbnA.esm.js.map +0 -1
  504. package/dist/chunks/tgaTextureLoader-6J7hFLap.esm.min.js +0 -2
  505. package/dist/chunks/tgaTextureLoader-6J7hFLap.esm.min.js.map +0 -1
  506. package/dist/chunks/tgaTextureLoader-C9bFUsSu.esm.js +0 -349
  507. package/dist/chunks/tgaTextureLoader-C9bFUsSu.esm.js.map +0 -1
  508. package/dist/chunks/thinInstanceMesh-01jRjs2y.esm.js +0 -314
  509. package/dist/chunks/thinInstanceMesh-01jRjs2y.esm.js.map +0 -1
  510. package/dist/chunks/thinInstanceMesh-BkM6bBqz.esm.min.js +0 -2
  511. package/dist/chunks/thinInstanceMesh-BkM6bBqz.esm.min.js.map +0 -1
  512. package/dist/chunks/vertexColorMixing-BQURABk9.esm.js +0 -528
  513. package/dist/chunks/vertexColorMixing-BQURABk9.esm.js.map +0 -1
  514. package/dist/chunks/vertexColorMixing-DtyijcYJ.esm.min.js +0 -2
  515. package/dist/chunks/vertexColorMixing-DtyijcYJ.esm.min.js.map +0 -1
  516. package/dist/chunks/workerPool-BUOov2K1.esm.js +0 -122
  517. package/dist/chunks/workerPool-BUOov2K1.esm.js.map +0 -1
  518. package/dist/chunks/workerPool-BWHiDmEZ.esm.min.js +0 -2
  519. package/dist/chunks/workerPool-BWHiDmEZ.esm.min.js.map +0 -1
  520. package/lib/index.d.ts +0 -237
  521. package/lib/index.js +0 -871
  522. package/lib/index.js.map +0 -1
@@ -1,1600 +0,0 @@
1
- import { a_ as _WarnImport, R as RegisterClass, aE as AbstractEngine, aq as Observable, b as Vector3, y as EngineStore, L as Logger, e as Tools, ak as unregisterGLTFExtension, al as registerGLTFExtension } from './index-CTNAO7X0.esm.js';
2
- import { ArrayItem, GLTFLoader } from './glTFLoader-DB7AOurF.esm.js';
3
- import './rawTexture-DzCCPFKA.esm.js';
4
- import './assetContainer-DVOdWL9b.esm.js';
5
- import './glTFLoaderAnimation-DK5fvCTY.esm.js';
6
-
7
- /**
8
- * Composed of a frame, and an action function
9
- */
10
- class AnimationEvent {
11
- /**
12
- * Initializes the animation event
13
- * @param frame The frame for which the event is triggered
14
- * @param action The event to perform when triggered
15
- * @param onlyOnce Specifies if the event should be triggered only once
16
- */
17
- constructor(
18
- /** The frame for which the event is triggered **/
19
- frame,
20
- /** The event to perform when triggered **/
21
- action,
22
- /** Specifies if the event should be triggered only once**/
23
- onlyOnce) {
24
- this.frame = frame;
25
- this.action = action;
26
- this.onlyOnce = onlyOnce;
27
- /**
28
- * Specifies if the animation event is done
29
- */
30
- this.isDone = false;
31
- }
32
- /** @internal */
33
- _clone() {
34
- return new AnimationEvent(this.frame, this.action, this.onlyOnce);
35
- }
36
- }
37
-
38
- /**
39
- * Defines a sound that can be played in the application.
40
- * The sound can either be an ambient track or a simple sound played in reaction to a user action.
41
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic
42
- */
43
- class Sound {
44
- /**
45
- * Does the sound loop after it finishes playing once.
46
- */
47
- get loop() {
48
- return this._loop;
49
- }
50
- set loop(value) {
51
- if (value === this._loop) {
52
- return;
53
- }
54
- this._loop = value;
55
- this.updateOptions({ loop: value });
56
- }
57
- /**
58
- * Gets the current time for the sound.
59
- */
60
- get currentTime() {
61
- if (this._htmlAudioElement) {
62
- return this._htmlAudioElement.currentTime;
63
- }
64
- if (AbstractEngine.audioEngine?.audioContext && (this.isPlaying || this.isPaused)) {
65
- // The `_currentTime` member is only updated when the sound is paused. Add the time since the last start
66
- // to get the actual current time.
67
- const timeSinceLastStart = this.isPaused ? 0 : AbstractEngine.audioEngine.audioContext.currentTime - this._startTime;
68
- return this._currentTime + timeSinceLastStart;
69
- }
70
- return 0;
71
- }
72
- /**
73
- * Does this sound enables spatial sound.
74
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
75
- */
76
- get spatialSound() {
77
- return this._spatialSound;
78
- }
79
- /**
80
- * Does this sound enables spatial sound.
81
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
82
- */
83
- set spatialSound(newValue) {
84
- if (newValue == this._spatialSound) {
85
- return;
86
- }
87
- const wasPlaying = this.isPlaying;
88
- this.pause();
89
- if (newValue) {
90
- this._spatialSound = newValue;
91
- this._updateSpatialParameters();
92
- }
93
- else {
94
- this._disableSpatialSound();
95
- }
96
- if (wasPlaying) {
97
- this.play();
98
- }
99
- }
100
- /**
101
- * Create a sound and attach it to a scene
102
- * @param name Name of your sound
103
- * @param urlOrArrayBuffer Url to the sound to load async or ArrayBuffer, it also works with MediaStreams and AudioBuffers
104
- * @param scene defines the scene the sound belongs to
105
- * @param readyToPlayCallback Provide a callback function if you'd like to load your code once the sound is ready to be played
106
- * @param options Objects to provide with the current available options: autoplay, loop, volume, spatialSound, maxDistance, rolloffFactor, refDistance, distanceModel, panningModel, streaming
107
- */
108
- constructor(name, urlOrArrayBuffer, scene, readyToPlayCallback = null, options) {
109
- /**
110
- * Does the sound autoplay once loaded.
111
- */
112
- this.autoplay = false;
113
- this._loop = false;
114
- /**
115
- * Does the sound use a custom attenuation curve to simulate the falloff
116
- * happening when the source gets further away from the camera.
117
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-your-own-custom-attenuation-function
118
- */
119
- this.useCustomAttenuation = false;
120
- /**
121
- * Is this sound currently played.
122
- */
123
- this.isPlaying = false;
124
- /**
125
- * Is this sound currently paused.
126
- */
127
- this.isPaused = false;
128
- /**
129
- * Define the reference distance the sound should be heard perfectly.
130
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
131
- */
132
- this.refDistance = 1;
133
- /**
134
- * Define the roll off factor of spatial sounds.
135
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
136
- */
137
- this.rolloffFactor = 1;
138
- /**
139
- * Define the max distance the sound should be heard (intensity just became 0 at this point).
140
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
141
- */
142
- this.maxDistance = 100;
143
- /**
144
- * Define the distance attenuation model the sound will follow.
145
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
146
- */
147
- this.distanceModel = "linear";
148
- /**
149
- * Gets or sets an object used to store user defined information for the sound.
150
- */
151
- this.metadata = null;
152
- /**
153
- * Observable event when the current playing sound finishes.
154
- */
155
- this.onEndedObservable = new Observable();
156
- this._spatialSound = false;
157
- this._panningModel = "equalpower";
158
- this._playbackRate = 1;
159
- this._streaming = false;
160
- this._startTime = 0;
161
- this._currentTime = 0;
162
- this._position = Vector3.Zero();
163
- this._localDirection = new Vector3(1, 0, 0);
164
- this._volume = 1;
165
- this._isReadyToPlay = false;
166
- this._isDirectional = false;
167
- // Used if you'd like to create a directional sound.
168
- // If not set, the sound will be omnidirectional
169
- this._coneInnerAngle = 360;
170
- this._coneOuterAngle = 360;
171
- this._coneOuterGain = 0;
172
- this._isOutputConnected = false;
173
- this._urlType = "Unknown";
174
- this.name = name;
175
- scene = scene || EngineStore.LastCreatedScene;
176
- if (!scene) {
177
- return;
178
- }
179
- this._scene = scene;
180
- Sound._SceneComponentInitialization(scene);
181
- this._readyToPlayCallback = readyToPlayCallback;
182
- // Default custom attenuation function is a linear attenuation
183
- // eslint-disable-next-line @typescript-eslint/no-unused-vars
184
- this._customAttenuationFunction = (currentVolume, currentDistance, maxDistance, refDistance, rolloffFactor) => {
185
- if (currentDistance < maxDistance) {
186
- return currentVolume * (1 - currentDistance / maxDistance);
187
- }
188
- else {
189
- return 0;
190
- }
191
- };
192
- if (options) {
193
- this.autoplay = options.autoplay || false;
194
- this._loop = options.loop || false;
195
- // if volume === 0, we need another way to check this option
196
- if (options.volume !== undefined) {
197
- this._volume = options.volume;
198
- }
199
- this._spatialSound = options.spatialSound ?? false;
200
- this.maxDistance = options.maxDistance ?? 100;
201
- this.useCustomAttenuation = options.useCustomAttenuation ?? false;
202
- this.rolloffFactor = options.rolloffFactor || 1;
203
- this.refDistance = options.refDistance || 1;
204
- this.distanceModel = options.distanceModel || "linear";
205
- this._playbackRate = options.playbackRate || 1;
206
- this._streaming = options.streaming ?? false;
207
- this._length = options.length;
208
- this._offset = options.offset;
209
- }
210
- if (AbstractEngine.audioEngine?.canUseWebAudio && AbstractEngine.audioEngine.audioContext) {
211
- this._soundGain = AbstractEngine.audioEngine.audioContext.createGain();
212
- this._soundGain.gain.value = this._volume;
213
- this._inputAudioNode = this._soundGain;
214
- this._outputAudioNode = this._soundGain;
215
- if (this._spatialSound) {
216
- this._createSpatialParameters();
217
- }
218
- this._scene.mainSoundTrack.addSound(this);
219
- let validParameter = true;
220
- // if no parameter is passed, you need to call setAudioBuffer yourself to prepare the sound
221
- if (urlOrArrayBuffer) {
222
- try {
223
- if (typeof urlOrArrayBuffer === "string") {
224
- this._urlType = "String";
225
- this._url = urlOrArrayBuffer;
226
- }
227
- else if (urlOrArrayBuffer instanceof ArrayBuffer) {
228
- this._urlType = "ArrayBuffer";
229
- }
230
- else if (urlOrArrayBuffer instanceof HTMLMediaElement) {
231
- this._urlType = "MediaElement";
232
- }
233
- else if (urlOrArrayBuffer instanceof MediaStream) {
234
- this._urlType = "MediaStream";
235
- }
236
- else if (urlOrArrayBuffer instanceof AudioBuffer) {
237
- this._urlType = "AudioBuffer";
238
- }
239
- else if (Array.isArray(urlOrArrayBuffer)) {
240
- this._urlType = "Array";
241
- }
242
- let urls = [];
243
- let codecSupportedFound = false;
244
- switch (this._urlType) {
245
- case "MediaElement":
246
- this._streaming = true;
247
- this._isReadyToPlay = true;
248
- this._streamingSource = AbstractEngine.audioEngine.audioContext.createMediaElementSource(urlOrArrayBuffer);
249
- if (this.autoplay) {
250
- this.play(0, this._offset, this._length);
251
- }
252
- if (this._readyToPlayCallback) {
253
- this._readyToPlayCallback();
254
- }
255
- break;
256
- case "MediaStream":
257
- this._streaming = true;
258
- this._isReadyToPlay = true;
259
- this._streamingSource = AbstractEngine.audioEngine.audioContext.createMediaStreamSource(urlOrArrayBuffer);
260
- if (this.autoplay) {
261
- this.play(0, this._offset, this._length);
262
- }
263
- if (this._readyToPlayCallback) {
264
- this._readyToPlayCallback();
265
- }
266
- break;
267
- case "ArrayBuffer":
268
- if (urlOrArrayBuffer.byteLength > 0) {
269
- codecSupportedFound = true;
270
- this._soundLoaded(urlOrArrayBuffer);
271
- }
272
- break;
273
- case "AudioBuffer":
274
- this._audioBufferLoaded(urlOrArrayBuffer);
275
- break;
276
- case "String":
277
- urls.push(urlOrArrayBuffer);
278
- // eslint-disable-next-line no-fallthrough
279
- case "Array":
280
- if (urls.length === 0) {
281
- urls = urlOrArrayBuffer;
282
- }
283
- // If we found a supported format, we load it immediately and stop the loop
284
- for (let i = 0; i < urls.length; i++) {
285
- const url = urls[i];
286
- codecSupportedFound =
287
- (options && options.skipCodecCheck) ||
288
- (url.indexOf(".mp3", url.length - 4) !== -1 && AbstractEngine.audioEngine.isMP3supported) ||
289
- (url.indexOf(".ogg", url.length - 4) !== -1 && AbstractEngine.audioEngine.isOGGsupported) ||
290
- url.indexOf(".wav", url.length - 4) !== -1 ||
291
- url.indexOf(".m4a", url.length - 4) !== -1 ||
292
- url.indexOf(".mp4", url.length - 4) !== -1 ||
293
- url.indexOf("blob:") !== -1;
294
- if (codecSupportedFound) {
295
- // Loading sound
296
- if (!this._streaming) {
297
- this._scene._loadFile(url, (data) => {
298
- this._soundLoaded(data);
299
- }, undefined, true, true, (exception) => {
300
- if (exception) {
301
- Logger.Error("XHR " + exception.status + " error on: " + url + ".");
302
- }
303
- Logger.Error("Sound creation aborted.");
304
- this._scene.mainSoundTrack.removeSound(this);
305
- });
306
- }
307
- // Streaming sound using HTML5 Audio tag
308
- else {
309
- this._htmlAudioElement = new Audio(url);
310
- this._htmlAudioElement.controls = false;
311
- this._htmlAudioElement.loop = this.loop;
312
- Tools.SetCorsBehavior(url, this._htmlAudioElement);
313
- this._htmlAudioElement.preload = "auto";
314
- this._htmlAudioElement.addEventListener("canplaythrough", () => {
315
- this._isReadyToPlay = true;
316
- if (this.autoplay) {
317
- this.play(0, this._offset, this._length);
318
- }
319
- if (this._readyToPlayCallback) {
320
- this._readyToPlayCallback();
321
- }
322
- });
323
- document.body.appendChild(this._htmlAudioElement);
324
- this._htmlAudioElement.load();
325
- }
326
- break;
327
- }
328
- }
329
- break;
330
- default:
331
- validParameter = false;
332
- break;
333
- }
334
- if (!validParameter) {
335
- Logger.Error("Parameter must be a URL to the sound, an Array of URLs (.mp3 & .ogg) or an ArrayBuffer of the sound.");
336
- }
337
- else {
338
- if (!codecSupportedFound) {
339
- this._isReadyToPlay = true;
340
- // Simulating a ready to play event to avoid breaking code path
341
- if (this._readyToPlayCallback) {
342
- setTimeout(() => {
343
- if (this._readyToPlayCallback) {
344
- this._readyToPlayCallback();
345
- }
346
- }, 1000);
347
- }
348
- }
349
- }
350
- }
351
- catch (ex) {
352
- Logger.Error("Unexpected error. Sound creation aborted.");
353
- this._scene.mainSoundTrack.removeSound(this);
354
- }
355
- }
356
- }
357
- else {
358
- // Adding an empty sound to avoid breaking audio calls for non Web Audio browsers
359
- this._scene.mainSoundTrack.addSound(this);
360
- if (AbstractEngine.audioEngine && !AbstractEngine.audioEngine.WarnedWebAudioUnsupported) {
361
- Logger.Error("Web Audio is not supported by your browser.");
362
- AbstractEngine.audioEngine.WarnedWebAudioUnsupported = true;
363
- }
364
- // Simulating a ready to play event to avoid breaking code for non web audio browsers
365
- if (this._readyToPlayCallback) {
366
- setTimeout(() => {
367
- if (this._readyToPlayCallback) {
368
- this._readyToPlayCallback();
369
- }
370
- }, 1000);
371
- }
372
- }
373
- }
374
- /**
375
- * Release the sound and its associated resources
376
- */
377
- dispose() {
378
- if (AbstractEngine.audioEngine?.canUseWebAudio) {
379
- if (this.isPlaying) {
380
- this.stop();
381
- }
382
- this._isReadyToPlay = false;
383
- if (this.soundTrackId === -1) {
384
- this._scene.mainSoundTrack.removeSound(this);
385
- }
386
- else if (this._scene.soundTracks) {
387
- this._scene.soundTracks[this.soundTrackId].removeSound(this);
388
- }
389
- if (this._soundGain) {
390
- this._soundGain.disconnect();
391
- this._soundGain = null;
392
- }
393
- if (this._soundPanner) {
394
- this._soundPanner.disconnect();
395
- this._soundPanner = null;
396
- }
397
- if (this._soundSource) {
398
- this._soundSource.disconnect();
399
- this._soundSource = null;
400
- }
401
- this._audioBuffer = null;
402
- if (this._htmlAudioElement) {
403
- this._htmlAudioElement.pause();
404
- this._htmlAudioElement.src = "";
405
- document.body.removeChild(this._htmlAudioElement);
406
- }
407
- if (this._streamingSource) {
408
- this._streamingSource.disconnect();
409
- }
410
- if (this._connectedTransformNode && this._registerFunc) {
411
- this._connectedTransformNode.unregisterAfterWorldMatrixUpdate(this._registerFunc);
412
- this._connectedTransformNode = null;
413
- }
414
- this._clearTimeoutsAndObservers();
415
- }
416
- }
417
- /**
418
- * Gets if the sounds is ready to be played or not.
419
- * @returns true if ready, otherwise false
420
- */
421
- isReady() {
422
- return this._isReadyToPlay;
423
- }
424
- /**
425
- * Get the current class name.
426
- * @returns current class name
427
- */
428
- getClassName() {
429
- return "Sound";
430
- }
431
- _audioBufferLoaded(buffer) {
432
- if (!AbstractEngine.audioEngine?.audioContext) {
433
- return;
434
- }
435
- this._audioBuffer = buffer;
436
- this._isReadyToPlay = true;
437
- if (this.autoplay) {
438
- this.play(0, this._offset, this._length);
439
- }
440
- if (this._readyToPlayCallback) {
441
- this._readyToPlayCallback();
442
- }
443
- }
444
- _soundLoaded(audioData) {
445
- if (!AbstractEngine.audioEngine?.audioContext) {
446
- return;
447
- }
448
- AbstractEngine.audioEngine.audioContext.decodeAudioData(audioData, (buffer) => {
449
- this._audioBufferLoaded(buffer);
450
- }, (err) => {
451
- Logger.Error("Error while decoding audio data for: " + this.name + " / Error: " + err);
452
- });
453
- }
454
- /**
455
- * Sets the data of the sound from an audiobuffer
456
- * @param audioBuffer The audioBuffer containing the data
457
- */
458
- setAudioBuffer(audioBuffer) {
459
- if (AbstractEngine.audioEngine?.canUseWebAudio) {
460
- this._audioBuffer = audioBuffer;
461
- this._isReadyToPlay = true;
462
- }
463
- }
464
- /**
465
- * Updates the current sounds options such as maxdistance, loop...
466
- * @param options A JSON object containing values named as the object properties
467
- */
468
- updateOptions(options) {
469
- if (options) {
470
- this.loop = options.loop ?? this.loop;
471
- this.maxDistance = options.maxDistance ?? this.maxDistance;
472
- this.useCustomAttenuation = options.useCustomAttenuation ?? this.useCustomAttenuation;
473
- this.rolloffFactor = options.rolloffFactor ?? this.rolloffFactor;
474
- this.refDistance = options.refDistance ?? this.refDistance;
475
- this.distanceModel = options.distanceModel ?? this.distanceModel;
476
- this._playbackRate = options.playbackRate ?? this._playbackRate;
477
- this._length = options.length ?? undefined;
478
- this.spatialSound = options.spatialSound ?? this._spatialSound;
479
- this._setOffset(options.offset ?? undefined);
480
- this.setVolume(options.volume ?? this._volume);
481
- this._updateSpatialParameters();
482
- if (this.isPlaying) {
483
- if (this._streaming && this._htmlAudioElement) {
484
- this._htmlAudioElement.playbackRate = this._playbackRate;
485
- if (this._htmlAudioElement.loop !== this.loop) {
486
- this._htmlAudioElement.loop = this.loop;
487
- }
488
- }
489
- else {
490
- if (this._soundSource) {
491
- this._soundSource.playbackRate.value = this._playbackRate;
492
- if (this._soundSource.loop !== this.loop) {
493
- this._soundSource.loop = this.loop;
494
- }
495
- if (this._offset !== undefined && this._soundSource.loopStart !== this._offset) {
496
- this._soundSource.loopStart = this._offset;
497
- }
498
- if (this._length !== undefined && this._length !== this._soundSource.loopEnd) {
499
- this._soundSource.loopEnd = (this._offset | 0) + this._length;
500
- }
501
- }
502
- }
503
- }
504
- }
505
- }
506
- _createSpatialParameters() {
507
- if (AbstractEngine.audioEngine?.canUseWebAudio && AbstractEngine.audioEngine.audioContext) {
508
- if (this._scene.headphone) {
509
- this._panningModel = "HRTF";
510
- }
511
- this._soundPanner = this._soundPanner ?? AbstractEngine.audioEngine.audioContext.createPanner();
512
- if (this._soundPanner && this._outputAudioNode) {
513
- this._updateSpatialParameters();
514
- this._soundPanner.connect(this._outputAudioNode);
515
- this._inputAudioNode = this._soundPanner;
516
- }
517
- }
518
- }
519
- _disableSpatialSound() {
520
- if (!this._spatialSound) {
521
- return;
522
- }
523
- this._inputAudioNode = this._soundGain;
524
- this._soundPanner?.disconnect();
525
- this._soundPanner = null;
526
- this._spatialSound = false;
527
- }
528
- _updateSpatialParameters() {
529
- if (!this._spatialSound) {
530
- return;
531
- }
532
- if (this._soundPanner) {
533
- if (this.useCustomAttenuation) {
534
- // Tricks to disable in a way embedded Web Audio attenuation
535
- this._soundPanner.distanceModel = "linear";
536
- this._soundPanner.maxDistance = Number.MAX_VALUE;
537
- this._soundPanner.refDistance = 1;
538
- this._soundPanner.rolloffFactor = 1;
539
- this._soundPanner.panningModel = this._panningModel;
540
- }
541
- else {
542
- this._soundPanner.distanceModel = this.distanceModel;
543
- this._soundPanner.maxDistance = this.maxDistance;
544
- this._soundPanner.refDistance = this.refDistance;
545
- this._soundPanner.rolloffFactor = this.rolloffFactor;
546
- this._soundPanner.panningModel = this._panningModel;
547
- }
548
- }
549
- else {
550
- this._createSpatialParameters();
551
- }
552
- }
553
- /**
554
- * Switch the panning model to HRTF:
555
- * Renders a stereo output of higher quality than equalpower — it uses a convolution with measured impulse responses from human subjects.
556
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
557
- */
558
- switchPanningModelToHRTF() {
559
- this._panningModel = "HRTF";
560
- this._switchPanningModel();
561
- }
562
- /**
563
- * Switch the panning model to Equal Power:
564
- * Represents the equal-power panning algorithm, generally regarded as simple and efficient. equalpower is the default value.
565
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
566
- */
567
- switchPanningModelToEqualPower() {
568
- this._panningModel = "equalpower";
569
- this._switchPanningModel();
570
- }
571
- _switchPanningModel() {
572
- if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
573
- this._soundPanner.panningModel = this._panningModel;
574
- }
575
- }
576
- /**
577
- * Connect this sound to a sound track audio node like gain...
578
- * @param soundTrackAudioNode the sound track audio node to connect to
579
- */
580
- connectToSoundTrackAudioNode(soundTrackAudioNode) {
581
- if (AbstractEngine.audioEngine?.canUseWebAudio && this._outputAudioNode) {
582
- if (this._isOutputConnected) {
583
- this._outputAudioNode.disconnect();
584
- }
585
- this._outputAudioNode.connect(soundTrackAudioNode);
586
- this._isOutputConnected = true;
587
- }
588
- }
589
- /**
590
- * Transform this sound into a directional source
591
- * @param coneInnerAngle Size of the inner cone in degree
592
- * @param coneOuterAngle Size of the outer cone in degree
593
- * @param coneOuterGain Volume of the sound outside the outer cone (between 0.0 and 1.0)
594
- */
595
- setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
596
- if (coneOuterAngle < coneInnerAngle) {
597
- Logger.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle.");
598
- return;
599
- }
600
- this._coneInnerAngle = coneInnerAngle;
601
- this._coneOuterAngle = coneOuterAngle;
602
- this._coneOuterGain = coneOuterGain;
603
- this._isDirectional = true;
604
- if (this.isPlaying && this.loop) {
605
- this.stop();
606
- this.play(0, this._offset, this._length);
607
- }
608
- }
609
- /**
610
- * Gets or sets the inner angle for the directional cone.
611
- */
612
- get directionalConeInnerAngle() {
613
- return this._coneInnerAngle;
614
- }
615
- /**
616
- * Gets or sets the inner angle for the directional cone.
617
- */
618
- set directionalConeInnerAngle(value) {
619
- if (value != this._coneInnerAngle) {
620
- if (this._coneOuterAngle < value) {
621
- Logger.Error("directionalConeInnerAngle: outer angle of the cone must be superior or equal to the inner angle.");
622
- return;
623
- }
624
- this._coneInnerAngle = value;
625
- if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
626
- this._soundPanner.coneInnerAngle = this._coneInnerAngle;
627
- }
628
- }
629
- }
630
- /**
631
- * Gets or sets the outer angle for the directional cone.
632
- */
633
- get directionalConeOuterAngle() {
634
- return this._coneOuterAngle;
635
- }
636
- /**
637
- * Gets or sets the outer angle for the directional cone.
638
- */
639
- set directionalConeOuterAngle(value) {
640
- if (value != this._coneOuterAngle) {
641
- if (value < this._coneInnerAngle) {
642
- Logger.Error("directionalConeOuterAngle: outer angle of the cone must be superior or equal to the inner angle.");
643
- return;
644
- }
645
- this._coneOuterAngle = value;
646
- if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
647
- this._soundPanner.coneOuterAngle = this._coneOuterAngle;
648
- }
649
- }
650
- }
651
- /**
652
- * Sets the position of the emitter if spatial sound is enabled
653
- * @param newPosition Defines the new position
654
- */
655
- setPosition(newPosition) {
656
- if (newPosition.equals(this._position)) {
657
- return;
658
- }
659
- this._position.copyFrom(newPosition);
660
- if (AbstractEngine.audioEngine?.canUseWebAudio &&
661
- this._spatialSound &&
662
- this._soundPanner &&
663
- !isNaN(this._position.x) &&
664
- !isNaN(this._position.y) &&
665
- !isNaN(this._position.z)) {
666
- this._soundPanner.positionX.value = this._position.x;
667
- this._soundPanner.positionY.value = this._position.y;
668
- this._soundPanner.positionZ.value = this._position.z;
669
- }
670
- }
671
- /**
672
- * Sets the local direction of the emitter if spatial sound is enabled
673
- * @param newLocalDirection Defines the new local direction
674
- */
675
- setLocalDirectionToMesh(newLocalDirection) {
676
- this._localDirection = newLocalDirection;
677
- if (AbstractEngine.audioEngine?.canUseWebAudio && this._connectedTransformNode && this.isPlaying) {
678
- this._updateDirection();
679
- }
680
- }
681
- _updateDirection() {
682
- if (!this._connectedTransformNode || !this._soundPanner) {
683
- return;
684
- }
685
- const mat = this._connectedTransformNode.getWorldMatrix();
686
- const direction = Vector3.TransformNormal(this._localDirection, mat);
687
- direction.normalize();
688
- this._soundPanner.orientationX.value = direction.x;
689
- this._soundPanner.orientationY.value = direction.y;
690
- this._soundPanner.orientationZ.value = direction.z;
691
- }
692
- /** @internal */
693
- updateDistanceFromListener() {
694
- if (AbstractEngine.audioEngine?.canUseWebAudio && this._connectedTransformNode && this.useCustomAttenuation && this._soundGain && this._scene.activeCamera) {
695
- const distance = this._scene.audioListenerPositionProvider
696
- ? this._connectedTransformNode.position.subtract(this._scene.audioListenerPositionProvider()).length()
697
- : this._connectedTransformNode.getDistanceToCamera(this._scene.activeCamera);
698
- this._soundGain.gain.value = this._customAttenuationFunction(this._volume, distance, this.maxDistance, this.refDistance, this.rolloffFactor);
699
- }
700
- }
701
- /**
702
- * Sets a new custom attenuation function for the sound.
703
- * @param callback Defines the function used for the attenuation
704
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-your-own-custom-attenuation-function
705
- */
706
- setAttenuationFunction(callback) {
707
- this._customAttenuationFunction = callback;
708
- }
709
- /**
710
- * Play the sound
711
- * @param time (optional) Start the sound after X seconds. Start immediately (0) by default.
712
- * @param offset (optional) Start the sound at a specific time in seconds
713
- * @param length (optional) Sound duration (in seconds)
714
- */
715
- play(time, offset, length) {
716
- if (this._isReadyToPlay && this._scene.audioEnabled && AbstractEngine.audioEngine?.audioContext) {
717
- try {
718
- this._clearTimeoutsAndObservers();
719
- let startTime = time ? AbstractEngine.audioEngine?.audioContext.currentTime + time : AbstractEngine.audioEngine?.audioContext.currentTime;
720
- if (!this._soundSource || !this._streamingSource) {
721
- if (this._spatialSound && this._soundPanner) {
722
- if (!isNaN(this._position.x) && !isNaN(this._position.y) && !isNaN(this._position.z)) {
723
- this._soundPanner.positionX.value = this._position.x;
724
- this._soundPanner.positionY.value = this._position.y;
725
- this._soundPanner.positionZ.value = this._position.z;
726
- }
727
- if (this._isDirectional) {
728
- this._soundPanner.coneInnerAngle = this._coneInnerAngle;
729
- this._soundPanner.coneOuterAngle = this._coneOuterAngle;
730
- this._soundPanner.coneOuterGain = this._coneOuterGain;
731
- if (this._connectedTransformNode) {
732
- this._updateDirection();
733
- }
734
- else {
735
- this._soundPanner.setOrientation(this._localDirection.x, this._localDirection.y, this._localDirection.z);
736
- }
737
- }
738
- }
739
- }
740
- if (this._streaming) {
741
- if (!this._streamingSource) {
742
- this._streamingSource = AbstractEngine.audioEngine.audioContext.createMediaElementSource(this._htmlAudioElement);
743
- this._htmlAudioElement.onended = () => {
744
- this._onended();
745
- };
746
- this._htmlAudioElement.playbackRate = this._playbackRate;
747
- }
748
- this._streamingSource.disconnect();
749
- if (this._inputAudioNode) {
750
- this._streamingSource.connect(this._inputAudioNode);
751
- }
752
- if (this._htmlAudioElement) {
753
- // required to manage properly the new suspended default state of Chrome
754
- // When the option 'streaming: true' is used, we need first to wait for
755
- // the audio engine to be unlocked by a user gesture before trying to play
756
- // an HTML Audio element
757
- const tryToPlay = () => {
758
- if (AbstractEngine.audioEngine?.unlocked) {
759
- const playPromise = this._htmlAudioElement.play();
760
- // In browsers that don’t yet support this functionality,
761
- // playPromise won’t be defined.
762
- if (playPromise !== undefined) {
763
- playPromise.catch(() => {
764
- // Automatic playback failed.
765
- // Waiting for the audio engine to be unlocked by user click on unmute
766
- AbstractEngine.audioEngine?.lock();
767
- if (this.loop || this.autoplay) {
768
- this._audioUnlockedObserver = AbstractEngine.audioEngine?.onAudioUnlockedObservable.addOnce(() => {
769
- tryToPlay();
770
- });
771
- }
772
- });
773
- }
774
- }
775
- else {
776
- if (this.loop || this.autoplay) {
777
- this._audioUnlockedObserver = AbstractEngine.audioEngine?.onAudioUnlockedObservable.addOnce(() => {
778
- tryToPlay();
779
- });
780
- }
781
- }
782
- };
783
- tryToPlay();
784
- }
785
- }
786
- else {
787
- const tryToPlay = () => {
788
- if (AbstractEngine.audioEngine?.audioContext) {
789
- length = length || this._length;
790
- if (offset !== undefined) {
791
- this._setOffset(offset);
792
- }
793
- if (this._soundSource) {
794
- const oldSource = this._soundSource;
795
- oldSource.onended = () => {
796
- oldSource.disconnect();
797
- };
798
- }
799
- this._soundSource = AbstractEngine.audioEngine?.audioContext.createBufferSource();
800
- if (this._soundSource && this._inputAudioNode) {
801
- this._soundSource.buffer = this._audioBuffer;
802
- this._soundSource.connect(this._inputAudioNode);
803
- this._soundSource.loop = this.loop;
804
- if (offset !== undefined) {
805
- this._soundSource.loopStart = offset;
806
- }
807
- if (length !== undefined) {
808
- this._soundSource.loopEnd = (offset | 0) + length;
809
- }
810
- this._soundSource.playbackRate.value = this._playbackRate;
811
- this._soundSource.onended = () => {
812
- this._onended();
813
- };
814
- startTime = time ? AbstractEngine.audioEngine?.audioContext.currentTime + time : AbstractEngine.audioEngine.audioContext.currentTime;
815
- const actualOffset = ((this.isPaused ? this.currentTime : 0) + (this._offset ?? 0)) % this._soundSource.buffer.duration;
816
- this._soundSource.start(startTime, actualOffset, this.loop ? undefined : length);
817
- }
818
- }
819
- };
820
- if (AbstractEngine.audioEngine?.audioContext.state === "suspended") {
821
- // Wait a bit for FF as context seems late to be ready.
822
- this._tryToPlayTimeout = setTimeout(() => {
823
- if (AbstractEngine.audioEngine?.audioContext.state === "suspended") {
824
- // Automatic playback failed.
825
- // Waiting for the audio engine to be unlocked by user click on unmute
826
- AbstractEngine.audioEngine.lock();
827
- if (this.loop || this.autoplay) {
828
- this._audioUnlockedObserver = AbstractEngine.audioEngine.onAudioUnlockedObservable.addOnce(() => {
829
- tryToPlay();
830
- });
831
- }
832
- }
833
- else {
834
- tryToPlay();
835
- }
836
- }, 500);
837
- }
838
- else {
839
- tryToPlay();
840
- }
841
- }
842
- this._startTime = startTime;
843
- this.isPlaying = true;
844
- this.isPaused = false;
845
- }
846
- catch (ex) {
847
- Logger.Error("Error while trying to play audio: " + this.name + ", " + ex.message);
848
- }
849
- }
850
- }
851
- _onended() {
852
- this.isPlaying = false;
853
- this._startTime = 0;
854
- this._currentTime = 0;
855
- if (this.onended) {
856
- this.onended();
857
- }
858
- this.onEndedObservable.notifyObservers(this);
859
- }
860
- /**
861
- * Stop the sound
862
- * @param time (optional) Stop the sound after X seconds. Stop immediately (0) by default.
863
- */
864
- stop(time) {
865
- if (this.isPlaying) {
866
- this._clearTimeoutsAndObservers();
867
- if (this._streaming) {
868
- if (this._htmlAudioElement) {
869
- this._htmlAudioElement.pause();
870
- // Test needed for Firefox or it will generate an Invalid State Error
871
- if (this._htmlAudioElement.currentTime > 0) {
872
- this._htmlAudioElement.currentTime = 0;
873
- }
874
- }
875
- else {
876
- this._streamingSource.disconnect();
877
- }
878
- this.isPlaying = false;
879
- }
880
- else if (AbstractEngine.audioEngine?.audioContext && this._soundSource) {
881
- const stopTime = time ? AbstractEngine.audioEngine.audioContext.currentTime + time : undefined;
882
- this._soundSource.onended = () => {
883
- this.isPlaying = false;
884
- this.isPaused = false;
885
- this._startTime = 0;
886
- this._currentTime = 0;
887
- if (this._soundSource) {
888
- this._soundSource.onended = () => void 0;
889
- }
890
- this._onended();
891
- };
892
- this._soundSource.stop(stopTime);
893
- }
894
- else {
895
- this.isPlaying = false;
896
- }
897
- }
898
- else if (this.isPaused) {
899
- this.isPaused = false;
900
- this._startTime = 0;
901
- this._currentTime = 0;
902
- }
903
- }
904
- /**
905
- * Put the sound in pause
906
- */
907
- pause() {
908
- if (this.isPlaying) {
909
- this._clearTimeoutsAndObservers();
910
- if (this._streaming) {
911
- if (this._htmlAudioElement) {
912
- this._htmlAudioElement.pause();
913
- }
914
- else {
915
- this._streamingSource.disconnect();
916
- }
917
- this.isPlaying = false;
918
- this.isPaused = true;
919
- }
920
- else if (AbstractEngine.audioEngine?.audioContext && this._soundSource) {
921
- this._soundSource.onended = () => void 0;
922
- this._soundSource.stop();
923
- this.isPlaying = false;
924
- this.isPaused = true;
925
- this._currentTime += AbstractEngine.audioEngine.audioContext.currentTime - this._startTime;
926
- }
927
- }
928
- }
929
- /**
930
- * Sets a dedicated volume for this sounds
931
- * @param newVolume Define the new volume of the sound
932
- * @param time Define time for gradual change to new volume
933
- */
934
- setVolume(newVolume, time) {
935
- if (AbstractEngine.audioEngine?.canUseWebAudio && this._soundGain) {
936
- if (time && AbstractEngine.audioEngine.audioContext) {
937
- this._soundGain.gain.cancelScheduledValues(AbstractEngine.audioEngine.audioContext.currentTime);
938
- this._soundGain.gain.setValueAtTime(this._soundGain.gain.value, AbstractEngine.audioEngine.audioContext.currentTime);
939
- this._soundGain.gain.linearRampToValueAtTime(newVolume, AbstractEngine.audioEngine.audioContext.currentTime + time);
940
- }
941
- else {
942
- this._soundGain.gain.value = newVolume;
943
- }
944
- }
945
- this._volume = newVolume;
946
- }
947
- /**
948
- * Set the sound play back rate
949
- * @param newPlaybackRate Define the playback rate the sound should be played at
950
- */
951
- setPlaybackRate(newPlaybackRate) {
952
- this._playbackRate = newPlaybackRate;
953
- if (this.isPlaying) {
954
- if (this._streaming && this._htmlAudioElement) {
955
- this._htmlAudioElement.playbackRate = this._playbackRate;
956
- }
957
- else if (this._soundSource) {
958
- this._soundSource.playbackRate.value = this._playbackRate;
959
- }
960
- }
961
- }
962
- /**
963
- * Gets the sound play back rate.
964
- * @returns the play back rate of the sound
965
- */
966
- getPlaybackRate() {
967
- return this._playbackRate;
968
- }
969
- /**
970
- * Gets the volume of the sound.
971
- * @returns the volume of the sound
972
- */
973
- getVolume() {
974
- return this._volume;
975
- }
976
- /**
977
- * Attach the sound to a dedicated mesh
978
- * @param transformNode The transform node to connect the sound with
979
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#attaching-a-sound-to-a-mesh
980
- */
981
- attachToMesh(transformNode) {
982
- if (this._connectedTransformNode && this._registerFunc) {
983
- this._connectedTransformNode.unregisterAfterWorldMatrixUpdate(this._registerFunc);
984
- this._registerFunc = null;
985
- }
986
- this._connectedTransformNode = transformNode;
987
- if (!this._spatialSound) {
988
- this._spatialSound = true;
989
- this._createSpatialParameters();
990
- if (this.isPlaying && this.loop) {
991
- this.stop();
992
- this.play(0, this._offset, this._length);
993
- }
994
- }
995
- this._onRegisterAfterWorldMatrixUpdate(this._connectedTransformNode);
996
- this._registerFunc = (transformNode) => this._onRegisterAfterWorldMatrixUpdate(transformNode);
997
- this._connectedTransformNode.registerAfterWorldMatrixUpdate(this._registerFunc);
998
- }
999
- /**
1000
- * Detach the sound from the previously attached mesh
1001
- * @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#attaching-a-sound-to-a-mesh
1002
- */
1003
- detachFromMesh() {
1004
- if (this._connectedTransformNode && this._registerFunc) {
1005
- this._connectedTransformNode.unregisterAfterWorldMatrixUpdate(this._registerFunc);
1006
- this._registerFunc = null;
1007
- this._connectedTransformNode = null;
1008
- }
1009
- }
1010
- _onRegisterAfterWorldMatrixUpdate(node) {
1011
- if (!node.getBoundingInfo) {
1012
- this.setPosition(node.absolutePosition);
1013
- }
1014
- else {
1015
- const mesh = node;
1016
- const boundingInfo = mesh.getBoundingInfo();
1017
- this.setPosition(boundingInfo.boundingSphere.centerWorld);
1018
- }
1019
- if (AbstractEngine.audioEngine?.canUseWebAudio && this._isDirectional && this.isPlaying) {
1020
- this._updateDirection();
1021
- }
1022
- }
1023
- /**
1024
- * Clone the current sound in the scene.
1025
- * @returns the new sound clone
1026
- */
1027
- clone() {
1028
- if (!this._streaming) {
1029
- const setBufferAndRun = () => {
1030
- if (this._isReadyToPlay) {
1031
- clonedSound._audioBuffer = this.getAudioBuffer();
1032
- clonedSound._isReadyToPlay = true;
1033
- if (clonedSound.autoplay) {
1034
- clonedSound.play(0, this._offset, this._length);
1035
- }
1036
- }
1037
- else {
1038
- setTimeout(setBufferAndRun, 300);
1039
- }
1040
- };
1041
- const currentOptions = {
1042
- autoplay: this.autoplay,
1043
- loop: this.loop,
1044
- volume: this._volume,
1045
- spatialSound: this._spatialSound,
1046
- maxDistance: this.maxDistance,
1047
- useCustomAttenuation: this.useCustomAttenuation,
1048
- rolloffFactor: this.rolloffFactor,
1049
- refDistance: this.refDistance,
1050
- distanceModel: this.distanceModel,
1051
- };
1052
- const clonedSound = new Sound(this.name + "_cloned", new ArrayBuffer(0), this._scene, null, currentOptions);
1053
- if (this.useCustomAttenuation) {
1054
- clonedSound.setAttenuationFunction(this._customAttenuationFunction);
1055
- }
1056
- clonedSound.setPosition(this._position);
1057
- clonedSound.setPlaybackRate(this._playbackRate);
1058
- setBufferAndRun();
1059
- return clonedSound;
1060
- }
1061
- // Can't clone a streaming sound
1062
- else {
1063
- return null;
1064
- }
1065
- }
1066
- /**
1067
- * Gets the current underlying audio buffer containing the data
1068
- * @returns the audio buffer
1069
- */
1070
- getAudioBuffer() {
1071
- return this._audioBuffer;
1072
- }
1073
- /**
1074
- * Gets the WebAudio AudioBufferSourceNode, lets you keep track of and stop instances of this Sound.
1075
- * @returns the source node
1076
- */
1077
- getSoundSource() {
1078
- return this._soundSource;
1079
- }
1080
- /**
1081
- * Gets the WebAudio GainNode, gives you precise control over the gain of instances of this Sound.
1082
- * @returns the gain node
1083
- */
1084
- getSoundGain() {
1085
- return this._soundGain;
1086
- }
1087
- /**
1088
- * Serializes the Sound in a JSON representation
1089
- * @returns the JSON representation of the sound
1090
- */
1091
- serialize() {
1092
- const serializationObject = {
1093
- name: this.name,
1094
- url: this._url,
1095
- autoplay: this.autoplay,
1096
- loop: this.loop,
1097
- volume: this._volume,
1098
- spatialSound: this._spatialSound,
1099
- maxDistance: this.maxDistance,
1100
- rolloffFactor: this.rolloffFactor,
1101
- refDistance: this.refDistance,
1102
- distanceModel: this.distanceModel,
1103
- playbackRate: this._playbackRate,
1104
- panningModel: this._panningModel,
1105
- soundTrackId: this.soundTrackId,
1106
- metadata: this.metadata,
1107
- };
1108
- if (this._spatialSound) {
1109
- if (this._connectedTransformNode) {
1110
- serializationObject.connectedMeshId = this._connectedTransformNode.id;
1111
- }
1112
- serializationObject.position = this._position.asArray();
1113
- serializationObject.refDistance = this.refDistance;
1114
- serializationObject.distanceModel = this.distanceModel;
1115
- serializationObject.isDirectional = this._isDirectional;
1116
- serializationObject.localDirectionToMesh = this._localDirection.asArray();
1117
- serializationObject.coneInnerAngle = this._coneInnerAngle;
1118
- serializationObject.coneOuterAngle = this._coneOuterAngle;
1119
- serializationObject.coneOuterGain = this._coneOuterGain;
1120
- }
1121
- return serializationObject;
1122
- }
1123
- /**
1124
- * Parse a JSON representation of a sound to instantiate in a given scene
1125
- * @param parsedSound Define the JSON representation of the sound (usually coming from the serialize method)
1126
- * @param scene Define the scene the new parsed sound should be created in
1127
- * @param rootUrl Define the rooturl of the load in case we need to fetch relative dependencies
1128
- * @param sourceSound Define a sound place holder if do not need to instantiate a new one
1129
- * @returns the newly parsed sound
1130
- */
1131
- static Parse(parsedSound, scene, rootUrl, sourceSound) {
1132
- const soundName = parsedSound.name;
1133
- let soundUrl;
1134
- if (parsedSound.url) {
1135
- soundUrl = rootUrl + parsedSound.url;
1136
- }
1137
- else {
1138
- soundUrl = rootUrl + soundName;
1139
- }
1140
- const options = {
1141
- autoplay: parsedSound.autoplay,
1142
- loop: parsedSound.loop,
1143
- volume: parsedSound.volume,
1144
- spatialSound: parsedSound.spatialSound,
1145
- maxDistance: parsedSound.maxDistance,
1146
- rolloffFactor: parsedSound.rolloffFactor,
1147
- refDistance: parsedSound.refDistance,
1148
- distanceModel: parsedSound.distanceModel,
1149
- playbackRate: parsedSound.playbackRate,
1150
- };
1151
- let newSound;
1152
- if (!sourceSound) {
1153
- newSound = new Sound(soundName, soundUrl, scene, () => {
1154
- scene.removePendingData(newSound);
1155
- }, options);
1156
- scene.addPendingData(newSound);
1157
- }
1158
- else {
1159
- const setBufferAndRun = () => {
1160
- if (sourceSound._isReadyToPlay) {
1161
- newSound._audioBuffer = sourceSound.getAudioBuffer();
1162
- newSound._isReadyToPlay = true;
1163
- if (newSound.autoplay) {
1164
- newSound.play(0, newSound._offset, newSound._length);
1165
- }
1166
- }
1167
- else {
1168
- setTimeout(setBufferAndRun, 300);
1169
- }
1170
- };
1171
- newSound = new Sound(soundName, new ArrayBuffer(0), scene, null, options);
1172
- setBufferAndRun();
1173
- }
1174
- if (parsedSound.position) {
1175
- const soundPosition = Vector3.FromArray(parsedSound.position);
1176
- newSound.setPosition(soundPosition);
1177
- }
1178
- if (parsedSound.isDirectional) {
1179
- newSound.setDirectionalCone(parsedSound.coneInnerAngle || 360, parsedSound.coneOuterAngle || 360, parsedSound.coneOuterGain || 0);
1180
- if (parsedSound.localDirectionToMesh) {
1181
- const localDirectionToMesh = Vector3.FromArray(parsedSound.localDirectionToMesh);
1182
- newSound.setLocalDirectionToMesh(localDirectionToMesh);
1183
- }
1184
- }
1185
- if (parsedSound.connectedMeshId) {
1186
- const connectedMesh = scene.getMeshById(parsedSound.connectedMeshId);
1187
- if (connectedMesh) {
1188
- newSound.attachToMesh(connectedMesh);
1189
- }
1190
- }
1191
- if (parsedSound.metadata) {
1192
- newSound.metadata = parsedSound.metadata;
1193
- }
1194
- return newSound;
1195
- }
1196
- _setOffset(value) {
1197
- if (this._offset === value) {
1198
- return;
1199
- }
1200
- if (this.isPaused) {
1201
- this.stop();
1202
- this.isPaused = false;
1203
- }
1204
- this._offset = value;
1205
- }
1206
- _clearTimeoutsAndObservers() {
1207
- if (this._tryToPlayTimeout) {
1208
- clearTimeout(this._tryToPlayTimeout);
1209
- this._tryToPlayTimeout = null;
1210
- }
1211
- if (this._audioUnlockedObserver) {
1212
- AbstractEngine.audioEngine?.onAudioUnlockedObservable.remove(this._audioUnlockedObserver);
1213
- this._audioUnlockedObserver = null;
1214
- }
1215
- }
1216
- }
1217
- /**
1218
- * @internal
1219
- */
1220
- Sound._SceneComponentInitialization = (_) => {
1221
- throw _WarnImport("AudioSceneComponent");
1222
- };
1223
- // Register Class Name
1224
- RegisterClass("BABYLON.Sound", Sound);
1225
-
1226
- /**
1227
- * Wraps one or more Sound objects and selects one with random weight for playback.
1228
- */
1229
- class WeightedSound {
1230
- /**
1231
- * Creates a new WeightedSound from the list of sounds given.
1232
- * @param loop When true a Sound will be selected and played when the current playing Sound completes.
1233
- * @param sounds Array of Sounds that will be selected from.
1234
- * @param weights Array of number values for selection weights; length must equal sounds, values will be normalized to 1
1235
- */
1236
- constructor(loop, sounds, weights) {
1237
- /** When true a Sound will be selected and played when the current playing Sound completes. */
1238
- this.loop = false;
1239
- this._coneInnerAngle = 360;
1240
- this._coneOuterAngle = 360;
1241
- this._volume = 1;
1242
- /** A Sound is currently playing. */
1243
- this.isPlaying = false;
1244
- /** A Sound is currently paused. */
1245
- this.isPaused = false;
1246
- this._sounds = [];
1247
- this._weights = [];
1248
- if (sounds.length !== weights.length) {
1249
- throw new Error("Sounds length does not equal weights length");
1250
- }
1251
- this.loop = loop;
1252
- this._weights = weights;
1253
- // Normalize the weights
1254
- let weightSum = 0;
1255
- for (const weight of weights) {
1256
- weightSum += weight;
1257
- }
1258
- const invWeightSum = weightSum > 0 ? 1 / weightSum : 0;
1259
- for (let i = 0; i < this._weights.length; i++) {
1260
- this._weights[i] *= invWeightSum;
1261
- }
1262
- this._sounds = sounds;
1263
- for (const sound of this._sounds) {
1264
- sound.onEndedObservable.add(() => {
1265
- this._onended();
1266
- });
1267
- }
1268
- }
1269
- /**
1270
- * The size of cone in degrees for a directional sound in which there will be no attenuation.
1271
- */
1272
- get directionalConeInnerAngle() {
1273
- return this._coneInnerAngle;
1274
- }
1275
- /**
1276
- * The size of cone in degrees for a directional sound in which there will be no attenuation.
1277
- */
1278
- set directionalConeInnerAngle(value) {
1279
- if (value !== this._coneInnerAngle) {
1280
- if (this._coneOuterAngle < value) {
1281
- Logger.Error("directionalConeInnerAngle: outer angle of the cone must be superior or equal to the inner angle.");
1282
- return;
1283
- }
1284
- this._coneInnerAngle = value;
1285
- for (const sound of this._sounds) {
1286
- sound.directionalConeInnerAngle = value;
1287
- }
1288
- }
1289
- }
1290
- /**
1291
- * Size of cone in degrees for a directional sound outside of which there will be no sound.
1292
- * Listener angles between innerAngle and outerAngle will falloff linearly.
1293
- */
1294
- get directionalConeOuterAngle() {
1295
- return this._coneOuterAngle;
1296
- }
1297
- /**
1298
- * Size of cone in degrees for a directional sound outside of which there will be no sound.
1299
- * Listener angles between innerAngle and outerAngle will falloff linearly.
1300
- */
1301
- set directionalConeOuterAngle(value) {
1302
- if (value !== this._coneOuterAngle) {
1303
- if (value < this._coneInnerAngle) {
1304
- Logger.Error("directionalConeOuterAngle: outer angle of the cone must be superior or equal to the inner angle.");
1305
- return;
1306
- }
1307
- this._coneOuterAngle = value;
1308
- for (const sound of this._sounds) {
1309
- sound.directionalConeOuterAngle = value;
1310
- }
1311
- }
1312
- }
1313
- /**
1314
- * Playback volume.
1315
- */
1316
- get volume() {
1317
- return this._volume;
1318
- }
1319
- /**
1320
- * Playback volume.
1321
- */
1322
- set volume(value) {
1323
- if (value !== this._volume) {
1324
- for (const sound of this._sounds) {
1325
- sound.setVolume(value);
1326
- }
1327
- }
1328
- }
1329
- _onended() {
1330
- if (this._currentIndex !== undefined) {
1331
- this._sounds[this._currentIndex].autoplay = false;
1332
- }
1333
- if (this.loop && this.isPlaying) {
1334
- this.play();
1335
- }
1336
- else {
1337
- this.isPlaying = false;
1338
- }
1339
- }
1340
- /**
1341
- * Suspend playback
1342
- */
1343
- pause() {
1344
- this.isPaused = true;
1345
- if (this._currentIndex !== undefined) {
1346
- this._sounds[this._currentIndex].pause();
1347
- }
1348
- }
1349
- /**
1350
- * Stop playback
1351
- */
1352
- stop() {
1353
- this.isPlaying = false;
1354
- if (this._currentIndex !== undefined) {
1355
- this._sounds[this._currentIndex].stop();
1356
- }
1357
- }
1358
- /**
1359
- * Start playback.
1360
- * @param startOffset Position the clip head at a specific time in seconds.
1361
- */
1362
- play(startOffset) {
1363
- if (!this.isPaused) {
1364
- this.stop();
1365
- const randomValue = Math.random();
1366
- let total = 0;
1367
- for (let i = 0; i < this._weights.length; i++) {
1368
- total += this._weights[i];
1369
- if (randomValue <= total) {
1370
- this._currentIndex = i;
1371
- break;
1372
- }
1373
- }
1374
- }
1375
- const sound = this._sounds[this._currentIndex];
1376
- if (sound.isReady()) {
1377
- sound.play(0, this.isPaused ? undefined : startOffset);
1378
- }
1379
- else {
1380
- sound.autoplay = true;
1381
- }
1382
- this.isPlaying = true;
1383
- this.isPaused = false;
1384
- }
1385
- }
1386
-
1387
- const NAME = "MSFT_audio_emitter";
1388
- /**
1389
- * [Specification](https://github.com/najadojo/glTF/blob/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter/README.md)
1390
- * !!! Experimental Extension Subject to Changes !!!
1391
- */
1392
- // eslint-disable-next-line @typescript-eslint/naming-convention
1393
- class MSFT_audio_emitter {
1394
- /**
1395
- * @internal
1396
- */
1397
- constructor(loader) {
1398
- /**
1399
- * The name of this extension.
1400
- */
1401
- this.name = NAME;
1402
- this._loader = loader;
1403
- this.enabled = this._loader.isExtensionUsed(NAME);
1404
- }
1405
- /** @internal */
1406
- dispose() {
1407
- this._loader = null;
1408
- this._clips = null;
1409
- this._emitters = null;
1410
- }
1411
- /** @internal */
1412
- onLoading() {
1413
- const extensions = this._loader.gltf.extensions;
1414
- if (extensions && extensions[this.name]) {
1415
- const extension = extensions[this.name];
1416
- this._clips = extension.clips;
1417
- this._emitters = extension.emitters;
1418
- ArrayItem.Assign(this._clips);
1419
- ArrayItem.Assign(this._emitters);
1420
- }
1421
- }
1422
- /**
1423
- * @internal
1424
- */
1425
- loadSceneAsync(context, scene) {
1426
- return GLTFLoader.LoadExtensionAsync(context, scene, this.name, (extensionContext, extension) => {
1427
- const promises = new Array();
1428
- promises.push(this._loader.loadSceneAsync(context, scene));
1429
- for (const emitterIndex of extension.emitters) {
1430
- const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);
1431
- if (emitter.refDistance != undefined ||
1432
- emitter.maxDistance != undefined ||
1433
- emitter.rolloffFactor != undefined ||
1434
- emitter.distanceModel != undefined ||
1435
- emitter.innerAngle != undefined ||
1436
- emitter.outerAngle != undefined) {
1437
- throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);
1438
- }
1439
- promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));
1440
- }
1441
- return Promise.all(promises).then(() => { });
1442
- });
1443
- }
1444
- /**
1445
- * @internal
1446
- */
1447
- loadNodeAsync(context, node, assign) {
1448
- return GLTFLoader.LoadExtensionAsync(context, node, this.name, (extensionContext, extension) => {
1449
- const promises = new Array();
1450
- return this._loader
1451
- .loadNodeAsync(extensionContext, node, (babylonMesh) => {
1452
- for (const emitterIndex of extension.emitters) {
1453
- const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);
1454
- promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {
1455
- for (const sound of emitter._babylonSounds) {
1456
- sound.attachToMesh(babylonMesh);
1457
- if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
1458
- sound.setLocalDirectionToMesh(Vector3.Forward());
1459
- sound.setDirectionalCone(2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
1460
- }
1461
- }
1462
- }));
1463
- }
1464
- assign(babylonMesh);
1465
- })
1466
- .then((babylonMesh) => {
1467
- return Promise.all(promises).then(() => {
1468
- return babylonMesh;
1469
- });
1470
- });
1471
- });
1472
- }
1473
- /**
1474
- * @internal
1475
- */
1476
- loadAnimationAsync(context, animation) {
1477
- return GLTFLoader.LoadExtensionAsync(context, animation, this.name, (extensionContext, extension) => {
1478
- return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {
1479
- const promises = new Array();
1480
- ArrayItem.Assign(extension.events);
1481
- for (const event of extension.events) {
1482
- promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));
1483
- }
1484
- return Promise.all(promises).then(() => {
1485
- return babylonAnimationGroup;
1486
- });
1487
- });
1488
- });
1489
- }
1490
- _loadClipAsync(context, clip) {
1491
- if (clip._objectURL) {
1492
- return clip._objectURL;
1493
- }
1494
- let promise;
1495
- if (clip.uri) {
1496
- promise = this._loader.loadUriAsync(context, clip, clip.uri);
1497
- }
1498
- else {
1499
- const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);
1500
- promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);
1501
- }
1502
- clip._objectURL = promise.then((data) => {
1503
- return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
1504
- });
1505
- return clip._objectURL;
1506
- }
1507
- _loadEmitterAsync(context, emitter) {
1508
- emitter._babylonSounds = emitter._babylonSounds || [];
1509
- if (!emitter._babylonData) {
1510
- const clipPromises = new Array();
1511
- const name = emitter.name || `emitter${emitter.index}`;
1512
- const options = {
1513
- loop: false,
1514
- autoplay: false,
1515
- volume: emitter.volume == undefined ? 1 : emitter.volume,
1516
- };
1517
- for (let i = 0; i < emitter.clips.length; i++) {
1518
- const clipContext = `/extensions/${this.name}/clips`;
1519
- const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);
1520
- clipPromises.push(this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL) => {
1521
- const sound = (emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options));
1522
- sound.refDistance = emitter.refDistance || 1;
1523
- sound.maxDistance = emitter.maxDistance || 256;
1524
- sound.rolloffFactor = emitter.rolloffFactor || 1;
1525
- sound.distanceModel = emitter.distanceModel || "exponential";
1526
- }));
1527
- }
1528
- const promise = Promise.all(clipPromises).then(() => {
1529
- const weights = emitter.clips.map((clip) => {
1530
- return clip.weight || 1;
1531
- });
1532
- const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);
1533
- if (emitter.innerAngle) {
1534
- weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);
1535
- }
1536
- if (emitter.outerAngle) {
1537
- weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);
1538
- }
1539
- if (emitter.volume) {
1540
- weightedSound.volume = emitter.volume;
1541
- }
1542
- emitter._babylonData.sound = weightedSound;
1543
- });
1544
- emitter._babylonData = {
1545
- loaded: promise,
1546
- };
1547
- }
1548
- return emitter._babylonData.loaded;
1549
- }
1550
- _getEventAction(context, sound, action, time, startOffset) {
1551
- switch (action) {
1552
- case "play" /* IMSFTAudioEmitter_AnimationEventAction.play */: {
1553
- return (currentFrame) => {
1554
- const frameOffset = (startOffset || 0) + (currentFrame - time);
1555
- sound.play(frameOffset);
1556
- };
1557
- }
1558
- case "stop" /* IMSFTAudioEmitter_AnimationEventAction.stop */: {
1559
- return () => {
1560
- sound.stop();
1561
- };
1562
- }
1563
- case "pause" /* IMSFTAudioEmitter_AnimationEventAction.pause */: {
1564
- return () => {
1565
- sound.pause();
1566
- };
1567
- }
1568
- default: {
1569
- throw new Error(`${context}: Unsupported action ${action}`);
1570
- }
1571
- }
1572
- }
1573
- _loadAnimationEventAsync(context, animationContext, animation, event, babylonAnimationGroup) {
1574
- if (babylonAnimationGroup.targetedAnimations.length == 0) {
1575
- return Promise.resolve();
1576
- }
1577
- const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
1578
- const emitterIndex = event.emitter;
1579
- const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);
1580
- return this._loadEmitterAsync(context, emitter).then(() => {
1581
- const sound = emitter._babylonData.sound;
1582
- if (sound) {
1583
- const babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));
1584
- babylonAnimation.animation.addEvent(babylonAnimationEvent);
1585
- // Make sure all started audio stops when this animation is terminated.
1586
- babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {
1587
- sound.stop();
1588
- });
1589
- babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {
1590
- sound.pause();
1591
- });
1592
- }
1593
- });
1594
- }
1595
- }
1596
- unregisterGLTFExtension(NAME);
1597
- registerGLTFExtension(NAME, true, (loader) => new MSFT_audio_emitter(loader));
1598
-
1599
- export { MSFT_audio_emitter };
1600
- //# sourceMappingURL=MSFT_audio_emitter-fFvTv2YK.esm.js.map