@babylonjs/viewer 7.24.0 → 7.25.0-alpha

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