@babylonjs/viewer 7.24.0-alpha → 7.24.0
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.
- package/configuration/configuration.d.ts +107 -0
- package/configuration/configuration.js +16 -0
- package/configuration/configuration.js.map +1 -0
- package/configuration/configurationCompatibility.d.ts +8 -0
- package/configuration/configurationCompatibility.js +66 -0
- package/configuration/configurationCompatibility.js.map +1 -0
- package/configuration/configurationContainer.d.ts +10 -0
- package/configuration/configurationContainer.js +10 -0
- package/configuration/configurationContainer.js.map +1 -0
- package/configuration/globals.d.ts +6 -0
- package/configuration/globals.js +18 -0
- package/configuration/globals.js.map +1 -0
- package/configuration/index.d.ts +2 -0
- package/configuration/index.js +4 -0
- package/configuration/index.js.map +1 -0
- package/configuration/interfaces/cameraConfiguration.d.ts +31 -0
- package/configuration/interfaces/cameraConfiguration.js +2 -0
- package/configuration/interfaces/cameraConfiguration.js.map +1 -0
- package/configuration/interfaces/colorGradingConfiguration.d.ts +81 -0
- package/configuration/interfaces/colorGradingConfiguration.js +2 -0
- package/configuration/interfaces/colorGradingConfiguration.js.map +1 -0
- package/configuration/interfaces/defaultRenderingPipelineConfiguration.d.ts +20 -0
- package/configuration/interfaces/defaultRenderingPipelineConfiguration.js +2 -0
- package/configuration/interfaces/defaultRenderingPipelineConfiguration.js.map +1 -0
- package/configuration/interfaces/environmentMapConfiguration.d.ts +22 -0
- package/configuration/interfaces/environmentMapConfiguration.js +2 -0
- package/configuration/interfaces/environmentMapConfiguration.js.map +1 -0
- package/configuration/interfaces/groundConfiguration.d.ts +24 -0
- package/configuration/interfaces/groundConfiguration.js +2 -0
- package/configuration/interfaces/groundConfiguration.js.map +1 -0
- package/configuration/interfaces/imageProcessingConfiguration.d.ts +45 -0
- package/configuration/interfaces/imageProcessingConfiguration.js +2 -0
- package/configuration/interfaces/imageProcessingConfiguration.js.map +1 -0
- package/configuration/interfaces/index.d.ts +15 -0
- package/configuration/interfaces/index.js +16 -0
- package/configuration/interfaces/index.js.map +1 -0
- package/configuration/interfaces/lightConfiguration.d.ts +60 -0
- package/configuration/interfaces/lightConfiguration.js +2 -0
- package/configuration/interfaces/lightConfiguration.js.map +1 -0
- package/configuration/interfaces/modelAnimationConfiguration.d.ts +26 -0
- package/configuration/interfaces/modelAnimationConfiguration.js +2 -0
- package/configuration/interfaces/modelAnimationConfiguration.js.map +1 -0
- package/configuration/interfaces/modelConfiguration.d.ts +65 -0
- package/configuration/interfaces/modelConfiguration.js +2 -0
- package/configuration/interfaces/modelConfiguration.js.map +1 -0
- package/configuration/interfaces/observersConfiguration.d.ts +5 -0
- package/configuration/interfaces/observersConfiguration.js +2 -0
- package/configuration/interfaces/observersConfiguration.js.map +1 -0
- package/configuration/interfaces/sceneConfiguration.d.ts +48 -0
- package/configuration/interfaces/sceneConfiguration.js +2 -0
- package/configuration/interfaces/sceneConfiguration.js.map +1 -0
- package/configuration/interfaces/sceneOptimizerConfiguration.d.ts +23 -0
- package/configuration/interfaces/sceneOptimizerConfiguration.js +2 -0
- package/configuration/interfaces/sceneOptimizerConfiguration.js.map +1 -0
- package/configuration/interfaces/skyboxConfiguration.d.ts +21 -0
- package/configuration/interfaces/skyboxConfiguration.js +2 -0
- package/configuration/interfaces/skyboxConfiguration.js.map +1 -0
- package/configuration/interfaces/templateConfiguration.d.ts +67 -0
- package/configuration/interfaces/templateConfiguration.js +2 -0
- package/configuration/interfaces/templateConfiguration.js.map +1 -0
- package/configuration/interfaces/vrConfiguration.d.ts +16 -0
- package/configuration/interfaces/vrConfiguration.js +2 -0
- package/configuration/interfaces/vrConfiguration.js.map +1 -0
- package/configuration/loader.d.ts +4 -0
- package/configuration/loader.js +17 -0
- package/configuration/loader.js.map +1 -0
- package/configuration/mappers.d.ts +43 -0
- package/configuration/mappers.js +192 -0
- package/configuration/mappers.js.map +1 -0
- package/configuration/renderOnlyLoader.d.ts +33 -0
- package/configuration/renderOnlyLoader.js +162 -0
- package/configuration/renderOnlyLoader.js.map +1 -0
- package/configuration/types/default.d.ts +6 -0
- package/configuration/types/default.js +121 -0
- package/configuration/types/default.js.map +1 -0
- package/configuration/types/environmentMap.d.ts +5 -0
- package/configuration/types/environmentMap.js +14 -0
- package/configuration/types/environmentMap.js.map +1 -0
- package/configuration/types/extended.d.ts +6 -0
- package/configuration/types/extended.js +317 -0
- package/configuration/types/extended.js.map +1 -0
- package/configuration/types/index.d.ts +14 -0
- package/configuration/types/index.js +51 -0
- package/configuration/types/index.js.map +1 -0
- package/configuration/types/minimal.d.ts +6 -0
- package/configuration/types/minimal.js +43 -0
- package/configuration/types/minimal.js.map +1 -0
- package/configuration/types/renderOnlyDefault.d.ts +30 -0
- package/configuration/types/renderOnlyDefault.js +31 -0
- package/configuration/types/renderOnlyDefault.js.map +1 -0
- package/configuration/types/shadowLight.d.ts +9 -0
- package/configuration/types/shadowLight.js +64 -0
- package/configuration/types/shadowLight.js.map +1 -0
- package/helper/index.d.ts +29 -0
- package/helper/index.js +66 -0
- package/helper/index.js.map +1 -0
- package/index.d.ts +30 -0
- package/index.js +46 -0
- package/index.js.map +1 -0
- package/initializer.d.ts +11 -0
- package/initializer.js +35 -0
- package/initializer.js.map +1 -0
- package/interfaces.d.ts +5 -0
- package/interfaces.js +7 -0
- package/interfaces.js.map +1 -0
- package/labs/environmentSerializer.d.ts +126 -0
- package/labs/environmentSerializer.js +191 -0
- package/labs/environmentSerializer.js.map +1 -0
- package/labs/texture.d.ts +183 -0
- package/labs/texture.js +351 -0
- package/labs/texture.js.map +1 -0
- package/labs/viewerLabs.d.ts +51 -0
- package/labs/viewerLabs.js +134 -0
- package/labs/viewerLabs.js.map +1 -0
- package/loader/modelLoader.d.ts +56 -0
- package/loader/modelLoader.js +199 -0
- package/loader/modelLoader.js.map +1 -0
- package/loader/plugins/applyMaterialConfig.d.ts +12 -0
- package/loader/plugins/applyMaterialConfig.js +16 -0
- package/loader/plugins/applyMaterialConfig.js.map +1 -0
- package/loader/plugins/extendedMaterialLoaderPlugin.d.ts +9 -0
- package/loader/plugins/extendedMaterialLoaderPlugin.js +16 -0
- package/loader/plugins/extendedMaterialLoaderPlugin.js.map +1 -0
- package/loader/plugins/index.d.ts +19 -0
- package/loader/plugins/index.js +44 -0
- package/loader/plugins/index.js.map +1 -0
- package/loader/plugins/loaderPlugin.d.ts +24 -0
- package/loader/plugins/loaderPlugin.js +2 -0
- package/loader/plugins/loaderPlugin.js.map +1 -0
- package/loader/plugins/msftLodLoaderPlugin.d.ts +12 -0
- package/loader/plugins/msftLodLoaderPlugin.js +21 -0
- package/loader/plugins/msftLodLoaderPlugin.js.map +1 -0
- package/loader/plugins/telemetryLoaderPlugin.d.ts +12 -0
- package/loader/plugins/telemetryLoaderPlugin.js +36 -0
- package/loader/plugins/telemetryLoaderPlugin.js.map +1 -0
- package/managers/observablesManager.d.ts +66 -0
- package/managers/observablesManager.js +35 -0
- package/managers/observablesManager.js.map +1 -0
- package/managers/sceneManager.d.ts +245 -0
- package/managers/sceneManager.js +1375 -0
- package/managers/sceneManager.js.map +1 -0
- package/managers/telemetryManager.d.ts +78 -0
- package/managers/telemetryManager.js +117 -0
- package/managers/telemetryManager.js.map +1 -0
- package/model/modelAnimation.d.ts +215 -0
- package/model/modelAnimation.js +237 -0
- package/model/modelAnimation.js.map +1 -0
- package/model/viewerModel.d.ts +233 -0
- package/model/viewerModel.js +673 -0
- package/model/viewerModel.js.map +1 -0
- package/optimizer/custom/extended.d.ts +13 -0
- package/optimizer/custom/extended.js +101 -0
- package/optimizer/custom/extended.js.map +1 -0
- package/optimizer/custom/index.d.ts +9 -0
- package/optimizer/custom/index.js +26 -0
- package/optimizer/custom/index.js.map +1 -0
- package/package.json +27 -17
- package/readme.md +21 -35
- package/renderOnlyIndex.d.ts +11 -0
- package/renderOnlyIndex.js +18 -0
- package/renderOnlyIndex.js.map +1 -0
- package/templating/eventManager.d.ts +35 -0
- package/templating/eventManager.js +66 -0
- package/templating/eventManager.js.map +1 -0
- package/templating/plugins/hdButtonPlugin.d.ts +9 -0
- package/templating/plugins/hdButtonPlugin.js +21 -0
- package/templating/plugins/hdButtonPlugin.js.map +1 -0
- package/templating/plugins/printButton.d.ts +9 -0
- package/templating/plugins/printButton.js +40 -0
- package/templating/plugins/printButton.js.map +1 -0
- package/templating/templateManager.d.ts +197 -0
- package/templating/templateManager.js +561 -0
- package/templating/templateManager.js.map +1 -0
- package/templating/viewerTemplatePlugin.d.ts +21 -0
- package/templating/viewerTemplatePlugin.js +69 -0
- package/templating/viewerTemplatePlugin.js.map +1 -0
- package/viewer/defaultViewer.d.ts +130 -0
- package/viewer/defaultViewer.js +675 -0
- package/viewer/defaultViewer.js.map +1 -0
- package/viewer/renderOnlyViewer.d.ts +9 -0
- package/viewer/renderOnlyViewer.js +46 -0
- package/viewer/renderOnlyViewer.js.map +1 -0
- package/viewer/viewer.d.ts +258 -0
- package/viewer/viewer.js +783 -0
- package/viewer/viewer.js.map +1 -0
- package/viewer/viewerManager.d.ts +58 -0
- package/viewer/viewerManager.js +91 -0
- package/viewer/viewerManager.js.map +1 -0
- package/viewer/viewerWithTemplate.d.ts +9 -0
- package/viewer/viewerWithTemplate.js +20 -0
- package/viewer/viewerWithTemplate.js.map +1 -0
- package/dist/babylon-viewer.esm.js +0 -2
- package/dist/babylon-viewer.esm.js.map +0 -1
- package/dist/babylon-viewer.esm.min.js +0 -2
- package/dist/babylon-viewer.esm.min.js.map +0 -1
- package/dist/chunks/EXT_lights_image_based-C8Zx_zbb.esm.min.js +0 -2
- package/dist/chunks/EXT_lights_image_based-C8Zx_zbb.esm.min.js.map +0 -1
- package/dist/chunks/EXT_lights_image_based-kduc1dpt.esm.js +0 -170
- package/dist/chunks/EXT_lights_image_based-kduc1dpt.esm.js.map +0 -1
- package/dist/chunks/EXT_mesh_gpu_instancing-CUpO919s.esm.min.js +0 -2
- package/dist/chunks/EXT_mesh_gpu_instancing-CUpO919s.esm.min.js.map +0 -1
- package/dist/chunks/EXT_mesh_gpu_instancing-CYGlESBG.esm.js +0 -86
- package/dist/chunks/EXT_mesh_gpu_instancing-CYGlESBG.esm.js.map +0 -1
- package/dist/chunks/EXT_meshopt_compression-BtWefmPI.esm.js +0 -134
- package/dist/chunks/EXT_meshopt_compression-BtWefmPI.esm.js.map +0 -1
- package/dist/chunks/EXT_meshopt_compression-DNd-1RJ_.esm.min.js +0 -2
- package/dist/chunks/EXT_meshopt_compression-DNd-1RJ_.esm.min.js.map +0 -1
- package/dist/chunks/EXT_texture_avif-BgOmraWM.esm.min.js +0 -2
- package/dist/chunks/EXT_texture_avif-BgOmraWM.esm.min.js.map +0 -1
- package/dist/chunks/EXT_texture_avif-BkBGixX6.esm.js +0 -44
- package/dist/chunks/EXT_texture_avif-BkBGixX6.esm.js.map +0 -1
- package/dist/chunks/EXT_texture_webp-DEij2Hfd.esm.min.js +0 -2
- package/dist/chunks/EXT_texture_webp-DEij2Hfd.esm.min.js.map +0 -1
- package/dist/chunks/EXT_texture_webp-Uw1qOCtv.esm.js +0 -43
- package/dist/chunks/EXT_texture_webp-Uw1qOCtv.esm.js.map +0 -1
- package/dist/chunks/ExtrasAsMetadata-BqsudUT7.esm.min.js +0 -2
- package/dist/chunks/ExtrasAsMetadata-BqsudUT7.esm.min.js.map +0 -1
- package/dist/chunks/ExtrasAsMetadata-CM2jTjHQ.esm.js +0 -64
- package/dist/chunks/ExtrasAsMetadata-CM2jTjHQ.esm.js.map +0 -1
- package/dist/chunks/KHR_animation_pointer-DX9lguJB.esm.js +0 -343
- package/dist/chunks/KHR_animation_pointer-DX9lguJB.esm.js.map +0 -1
- package/dist/chunks/KHR_animation_pointer-D_r3SXH0.esm.min.js +0 -2
- package/dist/chunks/KHR_animation_pointer-D_r3SXH0.esm.min.js.map +0 -1
- package/dist/chunks/KHR_draco_mesh_compression-Bxjw8_pv.esm.min.js +0 -2
- package/dist/chunks/KHR_draco_mesh_compression-Bxjw8_pv.esm.min.js.map +0 -1
- package/dist/chunks/KHR_draco_mesh_compression-CbI7tqZf.esm.js +0 -610
- package/dist/chunks/KHR_draco_mesh_compression-CbI7tqZf.esm.js.map +0 -1
- package/dist/chunks/KHR_interactivity-B9qhnhvi.esm.js +0 -4033
- package/dist/chunks/KHR_interactivity-B9qhnhvi.esm.js.map +0 -1
- package/dist/chunks/KHR_interactivity-ClkL8PwU.esm.min.js +0 -2
- package/dist/chunks/KHR_interactivity-ClkL8PwU.esm.min.js.map +0 -1
- package/dist/chunks/KHR_lights_punctual-C7-LlQCf.esm.js +0 -1253
- package/dist/chunks/KHR_lights_punctual-C7-LlQCf.esm.js.map +0 -1
- package/dist/chunks/KHR_lights_punctual-hn-7LTf-.esm.min.js +0 -2
- package/dist/chunks/KHR_lights_punctual-hn-7LTf-.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_anisotropy-B4Tuk6uT.esm.js +0 -64
- package/dist/chunks/KHR_materials_anisotropy-B4Tuk6uT.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_anisotropy-CKZ6ypYV.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_anisotropy-CKZ6ypYV.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_clearcoat-B7g-cV_Q.esm.js +0 -96
- package/dist/chunks/KHR_materials_clearcoat-B7g-cV_Q.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_clearcoat-BBlfAKyA.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_clearcoat-BBlfAKyA.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_diffuse_transmission-Cxa1EzSD.esm.js +0 -96
- package/dist/chunks/KHR_materials_diffuse_transmission-Cxa1EzSD.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_diffuse_transmission-D7VVR_6W.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_diffuse_transmission-D7VVR_6W.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_dispersion-BD-i4dhK.esm.js +0 -63
- package/dist/chunks/KHR_materials_dispersion-BD-i4dhK.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_dispersion-DA1pPYlo.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_dispersion-DA1pPYlo.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_emissive_strength-BUG2Suzu.esm.js +0 -55
- package/dist/chunks/KHR_materials_emissive_strength-BUG2Suzu.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_emissive_strength-Cy4f53O0.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_emissive_strength-Cy4f53O0.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_ior-CXkf52WI.esm.js +0 -64
- package/dist/chunks/KHR_materials_ior-CXkf52WI.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_ior-Cb18R0md.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_ior-Cb18R0md.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_iridescence-CRrr8cNQ.esm.js +0 -72
- package/dist/chunks/KHR_materials_iridescence-CRrr8cNQ.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_iridescence-RKidJoeM.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_iridescence-RKidJoeM.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_pbrSpecularGlossiness-CM3wFF_J.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_pbrSpecularGlossiness-CM3wFF_J.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_pbrSpecularGlossiness-JiRlMqAc.esm.js +0 -81
- package/dist/chunks/KHR_materials_pbrSpecularGlossiness-JiRlMqAc.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_sheen-CFE2-qvr.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_sheen-CFE2-qvr.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_sheen-yahUgSy0.esm.js +0 -85
- package/dist/chunks/KHR_materials_sheen-yahUgSy0.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_specular-D5MMqFRA.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_specular-D5MMqFRA.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_specular-uE0VOMMR.esm.js +0 -75
- package/dist/chunks/KHR_materials_specular-uE0VOMMR.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_transmission-BqfkbFTi.esm.js +0 -307
- package/dist/chunks/KHR_materials_transmission-BqfkbFTi.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_transmission-Cy5bbuBe.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_transmission-Cy5bbuBe.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_unlit-CeAe8MXr.esm.js +0 -74
- package/dist/chunks/KHR_materials_unlit-CeAe8MXr.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_unlit-D_vQV9wJ.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_unlit-D_vQV9wJ.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_variants-DI_pay4_.esm.js +0 -238
- package/dist/chunks/KHR_materials_variants-DI_pay4_.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_variants-jFCWO0BP.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_variants-jFCWO0BP.esm.min.js.map +0 -1
- package/dist/chunks/KHR_materials_volume-CeG8b15V.esm.js +0 -88
- package/dist/chunks/KHR_materials_volume-CeG8b15V.esm.js.map +0 -1
- package/dist/chunks/KHR_materials_volume-DE_Ylfcc.esm.min.js +0 -2
- package/dist/chunks/KHR_materials_volume-DE_Ylfcc.esm.min.js.map +0 -1
- package/dist/chunks/KHR_mesh_quantization-CzyL_Cnv.esm.js +0 -26
- package/dist/chunks/KHR_mesh_quantization-CzyL_Cnv.esm.js.map +0 -1
- package/dist/chunks/KHR_mesh_quantization-DJe_n3uT.esm.min.js +0 -2
- package/dist/chunks/KHR_mesh_quantization-DJe_n3uT.esm.min.js.map +0 -1
- package/dist/chunks/KHR_texture_basisu-BM_kwHpr.esm.min.js +0 -2
- package/dist/chunks/KHR_texture_basisu-BM_kwHpr.esm.min.js.map +0 -1
- package/dist/chunks/KHR_texture_basisu-CW33-gFJ.esm.js +0 -43
- package/dist/chunks/KHR_texture_basisu-CW33-gFJ.esm.js.map +0 -1
- package/dist/chunks/KHR_texture_transform-BvOVd3aP.esm.js +0 -63
- package/dist/chunks/KHR_texture_transform-BvOVd3aP.esm.js.map +0 -1
- package/dist/chunks/KHR_texture_transform-DP5URy2N.esm.min.js +0 -2
- package/dist/chunks/KHR_texture_transform-DP5URy2N.esm.min.js.map +0 -1
- package/dist/chunks/KHR_xmp_json_ld-BUxeQ4mX.esm.js +0 -51
- package/dist/chunks/KHR_xmp_json_ld-BUxeQ4mX.esm.js.map +0 -1
- package/dist/chunks/KHR_xmp_json_ld-CakdJpK8.esm.min.js +0 -2
- package/dist/chunks/KHR_xmp_json_ld-CakdJpK8.esm.min.js.map +0 -1
- package/dist/chunks/MSFT_audio_emitter-CANraFUR.esm.js +0 -1601
- package/dist/chunks/MSFT_audio_emitter-CANraFUR.esm.js.map +0 -1
- package/dist/chunks/MSFT_audio_emitter-CCZ2emXW.esm.min.js +0 -2
- package/dist/chunks/MSFT_audio_emitter-CCZ2emXW.esm.min.js.map +0 -1
- package/dist/chunks/MSFT_lod-B6edIFfM.esm.js +0 -337
- package/dist/chunks/MSFT_lod-B6edIFfM.esm.js.map +0 -1
- package/dist/chunks/MSFT_lod-CTqZxsr6.esm.min.js +0 -2
- package/dist/chunks/MSFT_lod-CTqZxsr6.esm.min.js.map +0 -1
- package/dist/chunks/MSFT_minecraftMesh-BQ2-yi3j.esm.min.js +0 -2
- package/dist/chunks/MSFT_minecraftMesh-BQ2-yi3j.esm.min.js.map +0 -1
- package/dist/chunks/MSFT_minecraftMesh-utO1z3Rb.esm.js +0 -46
- package/dist/chunks/MSFT_minecraftMesh-utO1z3Rb.esm.js.map +0 -1
- package/dist/chunks/MSFT_sRGBFactors-DcH5vUrm.esm.min.js +0 -2
- package/dist/chunks/MSFT_sRGBFactors-DcH5vUrm.esm.min.js.map +0 -1
- package/dist/chunks/MSFT_sRGBFactors-Dxlg_cnl.esm.js +0 -47
- package/dist/chunks/MSFT_sRGBFactors-Dxlg_cnl.esm.js.map +0 -1
- package/dist/chunks/assetContainer-D7kzzGaF.esm.js +0 -1598
- package/dist/chunks/assetContainer-D7kzzGaF.esm.js.map +0 -1
- package/dist/chunks/assetContainer-DerZknN4.esm.min.js +0 -2
- package/dist/chunks/assetContainer-DerZknN4.esm.min.js.map +0 -1
- package/dist/chunks/basisTextureLoader-DFUefcfx.esm.js +0 -600
- package/dist/chunks/basisTextureLoader-DFUefcfx.esm.js.map +0 -1
- package/dist/chunks/basisTextureLoader-DHZAViG3.esm.min.js +0 -2
- package/dist/chunks/basisTextureLoader-DHZAViG3.esm.min.js.map +0 -1
- package/dist/chunks/ddsTextureLoader-Besuv3in.esm.min.js +0 -2
- package/dist/chunks/ddsTextureLoader-Besuv3in.esm.min.js.map +0 -1
- package/dist/chunks/ddsTextureLoader-DAJtmdH2.esm.js +0 -87
- package/dist/chunks/ddsTextureLoader-DAJtmdH2.esm.js.map +0 -1
- package/dist/chunks/default.fragment-Byp0EQWo.esm.js +0 -452
- package/dist/chunks/default.fragment-Byp0EQWo.esm.js.map +0 -1
- package/dist/chunks/default.fragment-CPrwFLxj.esm.min.js +0 -2
- package/dist/chunks/default.fragment-CPrwFLxj.esm.min.js.map +0 -1
- package/dist/chunks/default.fragment-CuTK0g2w.esm.min.js +0 -2
- package/dist/chunks/default.fragment-CuTK0g2w.esm.min.js.map +0 -1
- package/dist/chunks/default.fragment-D4K678XE.esm.js +0 -515
- package/dist/chunks/default.fragment-D4K678XE.esm.js.map +0 -1
- package/dist/chunks/default.vertex-CBf60jXb.esm.js +0 -178
- package/dist/chunks/default.vertex-CBf60jXb.esm.js.map +0 -1
- package/dist/chunks/default.vertex-CPLi2rTa.esm.min.js +0 -2
- package/dist/chunks/default.vertex-CPLi2rTa.esm.min.js.map +0 -1
- package/dist/chunks/default.vertex-DneLJIzI.esm.js +0 -199
- package/dist/chunks/default.vertex-DneLJIzI.esm.js.map +0 -1
- package/dist/chunks/default.vertex-tjZYwgIm.esm.min.js +0 -2
- package/dist/chunks/default.vertex-tjZYwgIm.esm.min.js.map +0 -1
- package/dist/chunks/defaultUboDeclaration-5Ze2L4TA.esm.js +0 -15
- package/dist/chunks/defaultUboDeclaration-5Ze2L4TA.esm.js.map +0 -1
- package/dist/chunks/defaultUboDeclaration-BbZB9zOH.esm.min.js +0 -2
- package/dist/chunks/defaultUboDeclaration-BbZB9zOH.esm.min.js.map +0 -1
- package/dist/chunks/defaultUboDeclaration-C1D54TCU.esm.min.js +0 -2
- package/dist/chunks/defaultUboDeclaration-C1D54TCU.esm.min.js.map +0 -1
- package/dist/chunks/defaultUboDeclaration-xq351fzv.esm.js +0 -13
- package/dist/chunks/defaultUboDeclaration-xq351fzv.esm.js.map +0 -1
- package/dist/chunks/envTextureLoader-Cd87_F9v.esm.js +0 -63
- package/dist/chunks/envTextureLoader-Cd87_F9v.esm.js.map +0 -1
- package/dist/chunks/envTextureLoader-DDrwMoNn.esm.min.js +0 -2
- package/dist/chunks/envTextureLoader-DDrwMoNn.esm.min.js.map +0 -1
- package/dist/chunks/environmentTextureTools-Bewx0Dvk.esm.js +0 -381
- package/dist/chunks/environmentTextureTools-Bewx0Dvk.esm.js.map +0 -1
- package/dist/chunks/environmentTextureTools-CKR4vXo_.esm.min.js +0 -2
- package/dist/chunks/environmentTextureTools-CKR4vXo_.esm.min.js.map +0 -1
- package/dist/chunks/exrTextureLoader-B5OMTxNT.esm.min.js +0 -2
- package/dist/chunks/exrTextureLoader-B5OMTxNT.esm.min.js.map +0 -1
- package/dist/chunks/exrTextureLoader-DYief1aQ.esm.js +0 -1682
- package/dist/chunks/exrTextureLoader-DYief1aQ.esm.js.map +0 -1
- package/dist/chunks/fogFragment-DDtXY8BJ.esm.min.js +0 -2
- package/dist/chunks/fogFragment-DDtXY8BJ.esm.min.js.map +0 -1
- package/dist/chunks/fogFragment-uA_uzICI.esm.js +0 -102
- package/dist/chunks/fogFragment-uA_uzICI.esm.js.map +0 -1
- package/dist/chunks/glTFLoader-BYQ5K9Kt.esm.min.js +0 -2
- package/dist/chunks/glTFLoader-BYQ5K9Kt.esm.min.js.map +0 -1
- package/dist/chunks/glTFLoader-r35szQk2.esm.js +0 -7552
- package/dist/chunks/glTFLoader-r35szQk2.esm.js.map +0 -1
- package/dist/chunks/glTFLoaderAnimation-CBE8cJ5o.esm.min.js +0 -2
- package/dist/chunks/glTFLoaderAnimation-CBE8cJ5o.esm.min.js.map +0 -1
- package/dist/chunks/glTFLoaderAnimation-CT3NxYwM.esm.js +0 -77
- package/dist/chunks/glTFLoaderAnimation-CT3NxYwM.esm.js.map +0 -1
- package/dist/chunks/gltfPathToObjectConverter-Dyt_Y9jE.esm.min.js +0 -2
- package/dist/chunks/gltfPathToObjectConverter-Dyt_Y9jE.esm.min.js.map +0 -1
- package/dist/chunks/gltfPathToObjectConverter-GcUmfOyo.esm.js +0 -67
- package/dist/chunks/gltfPathToObjectConverter-GcUmfOyo.esm.js.map +0 -1
- package/dist/chunks/harmonicsFunctions-BFzEbNOc.esm.min.js +0 -2
- package/dist/chunks/harmonicsFunctions-BFzEbNOc.esm.min.js.map +0 -1
- package/dist/chunks/harmonicsFunctions-BmNqYWse.esm.js +0 -35
- package/dist/chunks/harmonicsFunctions-BmNqYWse.esm.js.map +0 -1
- package/dist/chunks/harmonicsFunctions-DCYVvJfE.esm.js +0 -34
- package/dist/chunks/harmonicsFunctions-DCYVvJfE.esm.js.map +0 -1
- package/dist/chunks/harmonicsFunctions-LdNe78Vv.esm.min.js +0 -2
- package/dist/chunks/harmonicsFunctions-LdNe78Vv.esm.min.js.map +0 -1
- package/dist/chunks/hdrTextureLoader-B4HJ1PIb.esm.js +0 -252
- package/dist/chunks/hdrTextureLoader-B4HJ1PIb.esm.js.map +0 -1
- package/dist/chunks/hdrTextureLoader-D2de5rCS.esm.min.js +0 -2
- package/dist/chunks/hdrTextureLoader-D2de5rCS.esm.min.js.map +0 -1
- package/dist/chunks/helperFunctions-B-V3wz1K.esm.js +0 -80
- package/dist/chunks/helperFunctions-B-V3wz1K.esm.js.map +0 -1
- package/dist/chunks/helperFunctions-B6u0LIQ1.esm.js +0 -108
- package/dist/chunks/helperFunctions-B6u0LIQ1.esm.js.map +0 -1
- package/dist/chunks/helperFunctions-D3_vTLCV.esm.min.js +0 -2
- package/dist/chunks/helperFunctions-D3_vTLCV.esm.min.js.map +0 -1
- package/dist/chunks/helperFunctions-DbaT8xhT.esm.min.js +0 -2
- package/dist/chunks/helperFunctions-DbaT8xhT.esm.min.js.map +0 -1
- package/dist/chunks/index-Bk29Qt-Y.esm.js +0 -81630
- package/dist/chunks/index-Bk29Qt-Y.esm.js.map +0 -1
- package/dist/chunks/index-BlF30_Ca.esm.min.js +0 -57
- package/dist/chunks/index-BlF30_Ca.esm.min.js.map +0 -1
- package/dist/chunks/ktxTextureLoader-BTMWrtOa.esm.js +0 -814
- package/dist/chunks/ktxTextureLoader-BTMWrtOa.esm.js.map +0 -1
- package/dist/chunks/ktxTextureLoader-OqiCvqqP.esm.min.js +0 -2
- package/dist/chunks/ktxTextureLoader-OqiCvqqP.esm.min.js.map +0 -1
- package/dist/chunks/logDepthDeclaration-BPKYewiS.esm.min.js +0 -2
- package/dist/chunks/logDepthDeclaration-BPKYewiS.esm.min.js.map +0 -1
- package/dist/chunks/logDepthDeclaration-CB6mwEV4.esm.min.js +0 -2
- package/dist/chunks/logDepthDeclaration-CB6mwEV4.esm.min.js.map +0 -1
- package/dist/chunks/logDepthDeclaration-CFTIeo9d.esm.js +0 -42
- package/dist/chunks/logDepthDeclaration-CFTIeo9d.esm.js.map +0 -1
- package/dist/chunks/logDepthDeclaration-DuXLlupN.esm.js +0 -35
- package/dist/chunks/logDepthDeclaration-DuXLlupN.esm.js.map +0 -1
- package/dist/chunks/logDepthVertex-B7lJf18n.esm.js +0 -605
- package/dist/chunks/logDepthVertex-B7lJf18n.esm.js.map +0 -1
- package/dist/chunks/logDepthVertex-BlpmPbMu.esm.min.js +0 -2
- package/dist/chunks/logDepthVertex-BlpmPbMu.esm.min.js.map +0 -1
- package/dist/chunks/logDepthVertex-CS2VncA3.esm.min.js +0 -2
- package/dist/chunks/logDepthVertex-CS2VncA3.esm.min.js.map +0 -1
- package/dist/chunks/logDepthVertex-DPI-wcrh.esm.js +0 -77
- package/dist/chunks/logDepthVertex-DPI-wcrh.esm.js.map +0 -1
- package/dist/chunks/mainUVVaryingDeclaration-B7jpQ5Mq.esm.min.js +0 -2
- package/dist/chunks/mainUVVaryingDeclaration-B7jpQ5Mq.esm.min.js.map +0 -1
- package/dist/chunks/mainUVVaryingDeclaration-Cy__-6Nq.esm.js +0 -11
- package/dist/chunks/mainUVVaryingDeclaration-Cy__-6Nq.esm.js.map +0 -1
- package/dist/chunks/objFileLoader-BQAlTWHc.esm.min.js +0 -2
- package/dist/chunks/objFileLoader-BQAlTWHc.esm.min.js.map +0 -1
- package/dist/chunks/objFileLoader-Bi8LHs3e.esm.js +0 -1280
- package/dist/chunks/objFileLoader-Bi8LHs3e.esm.js.map +0 -1
- package/dist/chunks/oitFragment-Bu6IB_U1.esm.min.js +0 -2
- package/dist/chunks/oitFragment-Bu6IB_U1.esm.min.js.map +0 -1
- package/dist/chunks/oitFragment-DWPsjeYm.esm.js +0 -1210
- package/dist/chunks/oitFragment-DWPsjeYm.esm.js.map +0 -1
- package/dist/chunks/oitFragment-DwS3p7os.esm.js +0 -1166
- package/dist/chunks/oitFragment-DwS3p7os.esm.js.map +0 -1
- package/dist/chunks/oitFragment-Dyo3GCIB.esm.min.js +0 -2
- package/dist/chunks/oitFragment-Dyo3GCIB.esm.min.js.map +0 -1
- package/dist/chunks/pass.fragment-BbvJLdK0.esm.min.js +0 -2
- package/dist/chunks/pass.fragment-BbvJLdK0.esm.min.js.map +0 -1
- package/dist/chunks/pass.fragment-CYW_mCe1.esm.js +0 -15
- package/dist/chunks/pass.fragment-CYW_mCe1.esm.js.map +0 -1
- package/dist/chunks/pbr.fragment-BF_ms0u4.esm.js +0 -3228
- package/dist/chunks/pbr.fragment-BF_ms0u4.esm.js.map +0 -1
- package/dist/chunks/pbr.fragment-BgRyNZP4.esm.min.js +0 -2
- package/dist/chunks/pbr.fragment-BgRyNZP4.esm.min.js.map +0 -1
- package/dist/chunks/pbr.fragment-DWDVg0cI.esm.js +0 -3163
- package/dist/chunks/pbr.fragment-DWDVg0cI.esm.js.map +0 -1
- package/dist/chunks/pbr.fragment-DnANKT1v.esm.min.js +0 -2
- package/dist/chunks/pbr.fragment-DnANKT1v.esm.min.js.map +0 -1
- package/dist/chunks/pbr.vertex-CtV1eMwZ.esm.js +0 -335
- package/dist/chunks/pbr.vertex-CtV1eMwZ.esm.js.map +0 -1
- package/dist/chunks/pbr.vertex-Dfv-0mcy.esm.js +0 -208
- package/dist/chunks/pbr.vertex-Dfv-0mcy.esm.js.map +0 -1
- package/dist/chunks/pbr.vertex-Dqkpv-Eq.esm.min.js +0 -2
- package/dist/chunks/pbr.vertex-Dqkpv-Eq.esm.min.js.map +0 -1
- package/dist/chunks/pbr.vertex-nSqzmuMh.esm.min.js +0 -2
- package/dist/chunks/pbr.vertex-nSqzmuMh.esm.min.js.map +0 -1
- package/dist/chunks/postprocess.vertex-CI-eDzvi.esm.js +0 -20
- package/dist/chunks/postprocess.vertex-CI-eDzvi.esm.js.map +0 -1
- package/dist/chunks/postprocess.vertex-Cs2SUWD0.esm.min.js +0 -2
- package/dist/chunks/postprocess.vertex-Cs2SUWD0.esm.min.js.map +0 -1
- package/dist/chunks/rawTexture-3oLvc_tp.esm.js +0 -562
- package/dist/chunks/rawTexture-3oLvc_tp.esm.js.map +0 -1
- package/dist/chunks/rawTexture-BWp9aJpK.esm.min.js +0 -2
- package/dist/chunks/rawTexture-BWp9aJpK.esm.min.js.map +0 -1
- package/dist/chunks/rgbdDecode.fragment-CYs1lXUB.esm.js +0 -17
- package/dist/chunks/rgbdDecode.fragment-CYs1lXUB.esm.js.map +0 -1
- package/dist/chunks/rgbdDecode.fragment-DiziHd4D.esm.min.js +0 -2
- package/dist/chunks/rgbdDecode.fragment-DiziHd4D.esm.min.js.map +0 -1
- package/dist/chunks/rgbdDecode.fragment-N_qzvKhN.esm.min.js +0 -2
- package/dist/chunks/rgbdDecode.fragment-N_qzvKhN.esm.min.js.map +0 -1
- package/dist/chunks/rgbdDecode.fragment-YPi0juk-.esm.js +0 -17
- package/dist/chunks/rgbdDecode.fragment-YPi0juk-.esm.js.map +0 -1
- package/dist/chunks/rgbdEncode.fragment-BPNHn1tT.esm.min.js +0 -2
- package/dist/chunks/rgbdEncode.fragment-BPNHn1tT.esm.min.js.map +0 -1
- package/dist/chunks/rgbdEncode.fragment-BcJhRtQ5.esm.min.js +0 -2
- package/dist/chunks/rgbdEncode.fragment-BcJhRtQ5.esm.min.js.map +0 -1
- package/dist/chunks/rgbdEncode.fragment-DtkOxT2Y.esm.js +0 -17
- package/dist/chunks/rgbdEncode.fragment-DtkOxT2Y.esm.js.map +0 -1
- package/dist/chunks/rgbdEncode.fragment-duKOXekg.esm.js +0 -17
- package/dist/chunks/rgbdEncode.fragment-duKOXekg.esm.js.map +0 -1
- package/dist/chunks/splatFileLoader-CftLaqSo.esm.js +0 -3137
- package/dist/chunks/splatFileLoader-CftLaqSo.esm.js.map +0 -1
- package/dist/chunks/splatFileLoader-DQY-vSa3.esm.min.js +0 -2
- package/dist/chunks/splatFileLoader-DQY-vSa3.esm.min.js.map +0 -1
- package/dist/chunks/standardMaterial-1c1C_ZIw.esm.js +0 -1809
- package/dist/chunks/standardMaterial-1c1C_ZIw.esm.js.map +0 -1
- package/dist/chunks/standardMaterial-CTSzlcu8.esm.min.js +0 -2
- package/dist/chunks/standardMaterial-CTSzlcu8.esm.min.js.map +0 -1
- package/dist/chunks/stlFileLoader-BGLYbFk2.esm.js +0 -237
- package/dist/chunks/stlFileLoader-BGLYbFk2.esm.js.map +0 -1
- package/dist/chunks/stlFileLoader-D451o5V4.esm.min.js +0 -2
- package/dist/chunks/stlFileLoader-D451o5V4.esm.min.js.map +0 -1
- package/dist/chunks/tgaTextureLoader-BLOklZDW.esm.min.js +0 -2
- package/dist/chunks/tgaTextureLoader-BLOklZDW.esm.min.js.map +0 -1
- package/dist/chunks/tgaTextureLoader-CCYZarL9.esm.js +0 -349
- package/dist/chunks/tgaTextureLoader-CCYZarL9.esm.js.map +0 -1
- package/dist/chunks/thinInstanceMesh-BuanMsAC.esm.min.js +0 -2
- package/dist/chunks/thinInstanceMesh-BuanMsAC.esm.min.js.map +0 -1
- package/dist/chunks/thinInstanceMesh-HVLKYr74.esm.js +0 -314
- package/dist/chunks/thinInstanceMesh-HVLKYr74.esm.js.map +0 -1
- package/dist/chunks/vertexColorMixing-Bhqvyjgc.esm.js +0 -528
- package/dist/chunks/vertexColorMixing-Bhqvyjgc.esm.js.map +0 -1
- package/dist/chunks/vertexColorMixing-Dgml7nXE.esm.min.js +0 -2
- package/dist/chunks/vertexColorMixing-Dgml7nXE.esm.min.js.map +0 -1
- package/dist/chunks/workerPool-BUOov2K1.esm.js +0 -122
- package/dist/chunks/workerPool-BUOov2K1.esm.js.map +0 -1
- package/dist/chunks/workerPool-BWHiDmEZ.esm.min.js +0 -2
- package/dist/chunks/workerPool-BWHiDmEZ.esm.min.js.map +0 -1
- package/lib/index.d.ts +0 -237
- package/lib/index.js +0 -871
- package/lib/index.js.map +0 -1
|
@@ -1,1601 +0,0 @@
|
|
|
1
|
-
import { a_ as _WarnImport, R as RegisterClass, aE as AbstractEngine, aq as Observable, b as Vector3, y as EngineStore, L as Logger, e as Tools, ak as unregisterGLTFExtension, al as registerGLTFExtension } from './index-Bk29Qt-Y.esm.js';
|
|
2
|
-
import { ArrayItem, GLTFLoader } from './glTFLoader-r35szQk2.esm.js';
|
|
3
|
-
import './rawTexture-3oLvc_tp.esm.js';
|
|
4
|
-
import './assetContainer-D7kzzGaF.esm.js';
|
|
5
|
-
import './glTFLoaderAnimation-CT3NxYwM.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
|
-
}
|
|
407
|
-
if (this._streamingSource) {
|
|
408
|
-
this._streamingSource.disconnect();
|
|
409
|
-
}
|
|
410
|
-
if (this._connectedTransformNode && this._registerFunc) {
|
|
411
|
-
this._connectedTransformNode.unregisterAfterWorldMatrixUpdate(this._registerFunc);
|
|
412
|
-
this._connectedTransformNode = null;
|
|
413
|
-
}
|
|
414
|
-
this._clearTimeoutsAndObservers();
|
|
415
|
-
}
|
|
416
|
-
}
|
|
417
|
-
/**
|
|
418
|
-
* Gets if the sounds is ready to be played or not.
|
|
419
|
-
* @returns true if ready, otherwise false
|
|
420
|
-
*/
|
|
421
|
-
isReady() {
|
|
422
|
-
return this._isReadyToPlay;
|
|
423
|
-
}
|
|
424
|
-
/**
|
|
425
|
-
* Get the current class name.
|
|
426
|
-
* @returns current class name
|
|
427
|
-
*/
|
|
428
|
-
getClassName() {
|
|
429
|
-
return "Sound";
|
|
430
|
-
}
|
|
431
|
-
_audioBufferLoaded(buffer) {
|
|
432
|
-
if (!AbstractEngine.audioEngine?.audioContext) {
|
|
433
|
-
return;
|
|
434
|
-
}
|
|
435
|
-
this._audioBuffer = buffer;
|
|
436
|
-
this._isReadyToPlay = true;
|
|
437
|
-
if (this.autoplay) {
|
|
438
|
-
this.play(0, this._offset, this._length);
|
|
439
|
-
}
|
|
440
|
-
if (this._readyToPlayCallback) {
|
|
441
|
-
this._readyToPlayCallback();
|
|
442
|
-
}
|
|
443
|
-
}
|
|
444
|
-
_soundLoaded(audioData) {
|
|
445
|
-
if (!AbstractEngine.audioEngine?.audioContext) {
|
|
446
|
-
return;
|
|
447
|
-
}
|
|
448
|
-
AbstractEngine.audioEngine.audioContext.decodeAudioData(audioData, (buffer) => {
|
|
449
|
-
this._audioBufferLoaded(buffer);
|
|
450
|
-
}, (err) => {
|
|
451
|
-
Logger.Error("Error while decoding audio data for: " + this.name + " / Error: " + err);
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
/**
|
|
455
|
-
* Sets the data of the sound from an audiobuffer
|
|
456
|
-
* @param audioBuffer The audioBuffer containing the data
|
|
457
|
-
*/
|
|
458
|
-
setAudioBuffer(audioBuffer) {
|
|
459
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio) {
|
|
460
|
-
this._audioBuffer = audioBuffer;
|
|
461
|
-
this._isReadyToPlay = true;
|
|
462
|
-
}
|
|
463
|
-
}
|
|
464
|
-
/**
|
|
465
|
-
* Updates the current sounds options such as maxdistance, loop...
|
|
466
|
-
* @param options A JSON object containing values named as the object properties
|
|
467
|
-
*/
|
|
468
|
-
updateOptions(options) {
|
|
469
|
-
if (options) {
|
|
470
|
-
this.loop = options.loop ?? this.loop;
|
|
471
|
-
this.maxDistance = options.maxDistance ?? this.maxDistance;
|
|
472
|
-
this.useCustomAttenuation = options.useCustomAttenuation ?? this.useCustomAttenuation;
|
|
473
|
-
this.rolloffFactor = options.rolloffFactor ?? this.rolloffFactor;
|
|
474
|
-
this.refDistance = options.refDistance ?? this.refDistance;
|
|
475
|
-
this.distanceModel = options.distanceModel ?? this.distanceModel;
|
|
476
|
-
this._playbackRate = options.playbackRate ?? this._playbackRate;
|
|
477
|
-
this._length = options.length ?? undefined;
|
|
478
|
-
this.spatialSound = options.spatialSound ?? this._spatialSound;
|
|
479
|
-
this._setOffset(options.offset ?? undefined);
|
|
480
|
-
this.setVolume(options.volume ?? this._volume);
|
|
481
|
-
this._updateSpatialParameters();
|
|
482
|
-
if (this.isPlaying) {
|
|
483
|
-
if (this._streaming && this._htmlAudioElement) {
|
|
484
|
-
this._htmlAudioElement.playbackRate = this._playbackRate;
|
|
485
|
-
if (this._htmlAudioElement.loop !== this.loop) {
|
|
486
|
-
this._htmlAudioElement.loop = this.loop;
|
|
487
|
-
}
|
|
488
|
-
}
|
|
489
|
-
else {
|
|
490
|
-
if (this._soundSource) {
|
|
491
|
-
this._soundSource.playbackRate.value = this._playbackRate;
|
|
492
|
-
if (this._soundSource.loop !== this.loop) {
|
|
493
|
-
this._soundSource.loop = this.loop;
|
|
494
|
-
}
|
|
495
|
-
if (this._offset !== undefined && this._soundSource.loopStart !== this._offset) {
|
|
496
|
-
this._soundSource.loopStart = this._offset;
|
|
497
|
-
}
|
|
498
|
-
if (this._length !== undefined && this._length !== this._soundSource.loopEnd) {
|
|
499
|
-
this._soundSource.loopEnd = (this._offset | 0) + this._length;
|
|
500
|
-
}
|
|
501
|
-
}
|
|
502
|
-
}
|
|
503
|
-
}
|
|
504
|
-
}
|
|
505
|
-
}
|
|
506
|
-
_createSpatialParameters() {
|
|
507
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && AbstractEngine.audioEngine.audioContext) {
|
|
508
|
-
if (this._scene.headphone) {
|
|
509
|
-
this._panningModel = "HRTF";
|
|
510
|
-
}
|
|
511
|
-
this._soundPanner = this._soundPanner ?? AbstractEngine.audioEngine.audioContext.createPanner();
|
|
512
|
-
if (this._soundPanner && this._outputAudioNode) {
|
|
513
|
-
this._updateSpatialParameters();
|
|
514
|
-
this._soundPanner.connect(this._outputAudioNode);
|
|
515
|
-
this._inputAudioNode = this._soundPanner;
|
|
516
|
-
}
|
|
517
|
-
}
|
|
518
|
-
}
|
|
519
|
-
_disableSpatialSound() {
|
|
520
|
-
if (!this._spatialSound) {
|
|
521
|
-
return;
|
|
522
|
-
}
|
|
523
|
-
this._inputAudioNode = this._soundGain;
|
|
524
|
-
this._soundPanner?.disconnect();
|
|
525
|
-
this._soundPanner = null;
|
|
526
|
-
this._spatialSound = false;
|
|
527
|
-
}
|
|
528
|
-
_updateSpatialParameters() {
|
|
529
|
-
if (!this._spatialSound) {
|
|
530
|
-
return;
|
|
531
|
-
}
|
|
532
|
-
if (this._soundPanner) {
|
|
533
|
-
if (this.useCustomAttenuation) {
|
|
534
|
-
// Tricks to disable in a way embedded Web Audio attenuation
|
|
535
|
-
this._soundPanner.distanceModel = "linear";
|
|
536
|
-
this._soundPanner.maxDistance = Number.MAX_VALUE;
|
|
537
|
-
this._soundPanner.refDistance = 1;
|
|
538
|
-
this._soundPanner.rolloffFactor = 1;
|
|
539
|
-
this._soundPanner.panningModel = this._panningModel;
|
|
540
|
-
}
|
|
541
|
-
else {
|
|
542
|
-
this._soundPanner.distanceModel = this.distanceModel;
|
|
543
|
-
this._soundPanner.maxDistance = this.maxDistance;
|
|
544
|
-
this._soundPanner.refDistance = this.refDistance;
|
|
545
|
-
this._soundPanner.rolloffFactor = this.rolloffFactor;
|
|
546
|
-
this._soundPanner.panningModel = this._panningModel;
|
|
547
|
-
}
|
|
548
|
-
}
|
|
549
|
-
else {
|
|
550
|
-
this._createSpatialParameters();
|
|
551
|
-
}
|
|
552
|
-
}
|
|
553
|
-
/**
|
|
554
|
-
* Switch the panning model to HRTF:
|
|
555
|
-
* Renders a stereo output of higher quality than equalpower — it uses a convolution with measured impulse responses from human subjects.
|
|
556
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
|
|
557
|
-
*/
|
|
558
|
-
switchPanningModelToHRTF() {
|
|
559
|
-
this._panningModel = "HRTF";
|
|
560
|
-
this._switchPanningModel();
|
|
561
|
-
}
|
|
562
|
-
/**
|
|
563
|
-
* Switch the panning model to Equal Power:
|
|
564
|
-
* Represents the equal-power panning algorithm, generally regarded as simple and efficient. equalpower is the default value.
|
|
565
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-a-spatial-3d-sound
|
|
566
|
-
*/
|
|
567
|
-
switchPanningModelToEqualPower() {
|
|
568
|
-
this._panningModel = "equalpower";
|
|
569
|
-
this._switchPanningModel();
|
|
570
|
-
}
|
|
571
|
-
_switchPanningModel() {
|
|
572
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
|
|
573
|
-
this._soundPanner.panningModel = this._panningModel;
|
|
574
|
-
}
|
|
575
|
-
}
|
|
576
|
-
/**
|
|
577
|
-
* Connect this sound to a sound track audio node like gain...
|
|
578
|
-
* @param soundTrackAudioNode the sound track audio node to connect to
|
|
579
|
-
*/
|
|
580
|
-
connectToSoundTrackAudioNode(soundTrackAudioNode) {
|
|
581
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && this._outputAudioNode) {
|
|
582
|
-
if (this._isOutputConnected) {
|
|
583
|
-
this._outputAudioNode.disconnect();
|
|
584
|
-
}
|
|
585
|
-
this._outputAudioNode.connect(soundTrackAudioNode);
|
|
586
|
-
this._isOutputConnected = true;
|
|
587
|
-
}
|
|
588
|
-
}
|
|
589
|
-
/**
|
|
590
|
-
* Transform this sound into a directional source
|
|
591
|
-
* @param coneInnerAngle Size of the inner cone in degree
|
|
592
|
-
* @param coneOuterAngle Size of the outer cone in degree
|
|
593
|
-
* @param coneOuterGain Volume of the sound outside the outer cone (between 0.0 and 1.0)
|
|
594
|
-
*/
|
|
595
|
-
setDirectionalCone(coneInnerAngle, coneOuterAngle, coneOuterGain) {
|
|
596
|
-
if (coneOuterAngle < coneInnerAngle) {
|
|
597
|
-
Logger.Error("setDirectionalCone(): outer angle of the cone must be superior or equal to the inner angle.");
|
|
598
|
-
return;
|
|
599
|
-
}
|
|
600
|
-
this._coneInnerAngle = coneInnerAngle;
|
|
601
|
-
this._coneOuterAngle = coneOuterAngle;
|
|
602
|
-
this._coneOuterGain = coneOuterGain;
|
|
603
|
-
this._isDirectional = true;
|
|
604
|
-
if (this.isPlaying && this.loop) {
|
|
605
|
-
this.stop();
|
|
606
|
-
this.play(0, this._offset, this._length);
|
|
607
|
-
}
|
|
608
|
-
}
|
|
609
|
-
/**
|
|
610
|
-
* Gets or sets the inner angle for the directional cone.
|
|
611
|
-
*/
|
|
612
|
-
get directionalConeInnerAngle() {
|
|
613
|
-
return this._coneInnerAngle;
|
|
614
|
-
}
|
|
615
|
-
/**
|
|
616
|
-
* Gets or sets the inner angle for the directional cone.
|
|
617
|
-
*/
|
|
618
|
-
set directionalConeInnerAngle(value) {
|
|
619
|
-
if (value != this._coneInnerAngle) {
|
|
620
|
-
if (this._coneOuterAngle < value) {
|
|
621
|
-
Logger.Error("directionalConeInnerAngle: outer angle of the cone must be superior or equal to the inner angle.");
|
|
622
|
-
return;
|
|
623
|
-
}
|
|
624
|
-
this._coneInnerAngle = value;
|
|
625
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
|
|
626
|
-
this._soundPanner.coneInnerAngle = this._coneInnerAngle;
|
|
627
|
-
}
|
|
628
|
-
}
|
|
629
|
-
}
|
|
630
|
-
/**
|
|
631
|
-
* Gets or sets the outer angle for the directional cone.
|
|
632
|
-
*/
|
|
633
|
-
get directionalConeOuterAngle() {
|
|
634
|
-
return this._coneOuterAngle;
|
|
635
|
-
}
|
|
636
|
-
/**
|
|
637
|
-
* Gets or sets the outer angle for the directional cone.
|
|
638
|
-
*/
|
|
639
|
-
set directionalConeOuterAngle(value) {
|
|
640
|
-
if (value != this._coneOuterAngle) {
|
|
641
|
-
if (value < this._coneInnerAngle) {
|
|
642
|
-
Logger.Error("directionalConeOuterAngle: outer angle of the cone must be superior or equal to the inner angle.");
|
|
643
|
-
return;
|
|
644
|
-
}
|
|
645
|
-
this._coneOuterAngle = value;
|
|
646
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
|
|
647
|
-
this._soundPanner.coneOuterAngle = this._coneOuterAngle;
|
|
648
|
-
}
|
|
649
|
-
}
|
|
650
|
-
}
|
|
651
|
-
/**
|
|
652
|
-
* Sets the position of the emitter if spatial sound is enabled
|
|
653
|
-
* @param newPosition Defines the new position
|
|
654
|
-
*/
|
|
655
|
-
setPosition(newPosition) {
|
|
656
|
-
if (newPosition.equals(this._position)) {
|
|
657
|
-
return;
|
|
658
|
-
}
|
|
659
|
-
this._position.copyFrom(newPosition);
|
|
660
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio &&
|
|
661
|
-
this._spatialSound &&
|
|
662
|
-
this._soundPanner &&
|
|
663
|
-
!isNaN(this._position.x) &&
|
|
664
|
-
!isNaN(this._position.y) &&
|
|
665
|
-
!isNaN(this._position.z)) {
|
|
666
|
-
this._soundPanner.positionX.value = this._position.x;
|
|
667
|
-
this._soundPanner.positionY.value = this._position.y;
|
|
668
|
-
this._soundPanner.positionZ.value = this._position.z;
|
|
669
|
-
}
|
|
670
|
-
}
|
|
671
|
-
/**
|
|
672
|
-
* Sets the local direction of the emitter if spatial sound is enabled
|
|
673
|
-
* @param newLocalDirection Defines the new local direction
|
|
674
|
-
*/
|
|
675
|
-
setLocalDirectionToMesh(newLocalDirection) {
|
|
676
|
-
this._localDirection = newLocalDirection;
|
|
677
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && this._connectedTransformNode && this.isPlaying) {
|
|
678
|
-
this._updateDirection();
|
|
679
|
-
}
|
|
680
|
-
}
|
|
681
|
-
_updateDirection() {
|
|
682
|
-
if (!this._connectedTransformNode || !this._soundPanner) {
|
|
683
|
-
return;
|
|
684
|
-
}
|
|
685
|
-
const mat = this._connectedTransformNode.getWorldMatrix();
|
|
686
|
-
const direction = Vector3.TransformNormal(this._localDirection, mat);
|
|
687
|
-
direction.normalize();
|
|
688
|
-
this._soundPanner.orientationX.value = direction.x;
|
|
689
|
-
this._soundPanner.orientationY.value = direction.y;
|
|
690
|
-
this._soundPanner.orientationZ.value = direction.z;
|
|
691
|
-
}
|
|
692
|
-
/** @internal */
|
|
693
|
-
updateDistanceFromListener() {
|
|
694
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && this._connectedTransformNode && this.useCustomAttenuation && this._soundGain && this._scene.activeCamera) {
|
|
695
|
-
const distance = this._scene.audioListenerPositionProvider
|
|
696
|
-
? this._connectedTransformNode.position.subtract(this._scene.audioListenerPositionProvider()).length()
|
|
697
|
-
: this._connectedTransformNode.getDistanceToCamera(this._scene.activeCamera);
|
|
698
|
-
this._soundGain.gain.value = this._customAttenuationFunction(this._volume, distance, this.maxDistance, this.refDistance, this.rolloffFactor);
|
|
699
|
-
}
|
|
700
|
-
}
|
|
701
|
-
/**
|
|
702
|
-
* Sets a new custom attenuation function for the sound.
|
|
703
|
-
* @param callback Defines the function used for the attenuation
|
|
704
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#creating-your-own-custom-attenuation-function
|
|
705
|
-
*/
|
|
706
|
-
setAttenuationFunction(callback) {
|
|
707
|
-
this._customAttenuationFunction = callback;
|
|
708
|
-
}
|
|
709
|
-
/**
|
|
710
|
-
* Play the sound
|
|
711
|
-
* @param time (optional) Start the sound after X seconds. Start immediately (0) by default.
|
|
712
|
-
* @param offset (optional) Start the sound at a specific time in seconds
|
|
713
|
-
* @param length (optional) Sound duration (in seconds)
|
|
714
|
-
*/
|
|
715
|
-
play(time, offset, length) {
|
|
716
|
-
if (this._isReadyToPlay && this._scene.audioEnabled && AbstractEngine.audioEngine?.audioContext) {
|
|
717
|
-
try {
|
|
718
|
-
this._clearTimeoutsAndObservers();
|
|
719
|
-
let startTime = time ? AbstractEngine.audioEngine?.audioContext.currentTime + time : AbstractEngine.audioEngine?.audioContext.currentTime;
|
|
720
|
-
if (!this._soundSource || !this._streamingSource) {
|
|
721
|
-
if (this._spatialSound && this._soundPanner) {
|
|
722
|
-
if (!isNaN(this._position.x) && !isNaN(this._position.y) && !isNaN(this._position.z)) {
|
|
723
|
-
this._soundPanner.positionX.value = this._position.x;
|
|
724
|
-
this._soundPanner.positionY.value = this._position.y;
|
|
725
|
-
this._soundPanner.positionZ.value = this._position.z;
|
|
726
|
-
}
|
|
727
|
-
if (this._isDirectional) {
|
|
728
|
-
this._soundPanner.coneInnerAngle = this._coneInnerAngle;
|
|
729
|
-
this._soundPanner.coneOuterAngle = this._coneOuterAngle;
|
|
730
|
-
this._soundPanner.coneOuterGain = this._coneOuterGain;
|
|
731
|
-
if (this._connectedTransformNode) {
|
|
732
|
-
this._updateDirection();
|
|
733
|
-
}
|
|
734
|
-
else {
|
|
735
|
-
this._soundPanner.setOrientation(this._localDirection.x, this._localDirection.y, this._localDirection.z);
|
|
736
|
-
}
|
|
737
|
-
}
|
|
738
|
-
}
|
|
739
|
-
}
|
|
740
|
-
if (this._streaming) {
|
|
741
|
-
if (!this._streamingSource) {
|
|
742
|
-
this._streamingSource = AbstractEngine.audioEngine.audioContext.createMediaElementSource(this._htmlAudioElement);
|
|
743
|
-
this._htmlAudioElement.onended = () => {
|
|
744
|
-
this._onended();
|
|
745
|
-
};
|
|
746
|
-
this._htmlAudioElement.playbackRate = this._playbackRate;
|
|
747
|
-
}
|
|
748
|
-
this._streamingSource.disconnect();
|
|
749
|
-
if (this._inputAudioNode) {
|
|
750
|
-
this._streamingSource.connect(this._inputAudioNode);
|
|
751
|
-
}
|
|
752
|
-
if (this._htmlAudioElement) {
|
|
753
|
-
// required to manage properly the new suspended default state of Chrome
|
|
754
|
-
// When the option 'streaming: true' is used, we need first to wait for
|
|
755
|
-
// the audio engine to be unlocked by a user gesture before trying to play
|
|
756
|
-
// an HTML Audio element
|
|
757
|
-
const tryToPlay = () => {
|
|
758
|
-
if (AbstractEngine.audioEngine?.unlocked) {
|
|
759
|
-
this._htmlAudioElement.currentTime = offset ?? 0;
|
|
760
|
-
const playPromise = this._htmlAudioElement.play();
|
|
761
|
-
// In browsers that don’t yet support this functionality,
|
|
762
|
-
// playPromise won’t be defined.
|
|
763
|
-
if (playPromise !== undefined) {
|
|
764
|
-
playPromise.catch(() => {
|
|
765
|
-
// Automatic playback failed.
|
|
766
|
-
// Waiting for the audio engine to be unlocked by user click on unmute
|
|
767
|
-
AbstractEngine.audioEngine?.lock();
|
|
768
|
-
if (this.loop || this.autoplay) {
|
|
769
|
-
this._audioUnlockedObserver = AbstractEngine.audioEngine?.onAudioUnlockedObservable.addOnce(() => {
|
|
770
|
-
tryToPlay();
|
|
771
|
-
});
|
|
772
|
-
}
|
|
773
|
-
});
|
|
774
|
-
}
|
|
775
|
-
}
|
|
776
|
-
else {
|
|
777
|
-
if (this.loop || this.autoplay) {
|
|
778
|
-
this._audioUnlockedObserver = AbstractEngine.audioEngine?.onAudioUnlockedObservable.addOnce(() => {
|
|
779
|
-
tryToPlay();
|
|
780
|
-
});
|
|
781
|
-
}
|
|
782
|
-
}
|
|
783
|
-
};
|
|
784
|
-
tryToPlay();
|
|
785
|
-
}
|
|
786
|
-
}
|
|
787
|
-
else {
|
|
788
|
-
const tryToPlay = () => {
|
|
789
|
-
if (AbstractEngine.audioEngine?.audioContext) {
|
|
790
|
-
length = length || this._length;
|
|
791
|
-
if (offset !== undefined) {
|
|
792
|
-
this._setOffset(offset);
|
|
793
|
-
}
|
|
794
|
-
if (this._soundSource) {
|
|
795
|
-
const oldSource = this._soundSource;
|
|
796
|
-
oldSource.onended = () => {
|
|
797
|
-
oldSource.disconnect();
|
|
798
|
-
};
|
|
799
|
-
}
|
|
800
|
-
this._soundSource = AbstractEngine.audioEngine?.audioContext.createBufferSource();
|
|
801
|
-
if (this._soundSource && this._inputAudioNode) {
|
|
802
|
-
this._soundSource.buffer = this._audioBuffer;
|
|
803
|
-
this._soundSource.connect(this._inputAudioNode);
|
|
804
|
-
this._soundSource.loop = this.loop;
|
|
805
|
-
if (offset !== undefined) {
|
|
806
|
-
this._soundSource.loopStart = offset;
|
|
807
|
-
}
|
|
808
|
-
if (length !== undefined) {
|
|
809
|
-
this._soundSource.loopEnd = (offset | 0) + length;
|
|
810
|
-
}
|
|
811
|
-
this._soundSource.playbackRate.value = this._playbackRate;
|
|
812
|
-
this._soundSource.onended = () => {
|
|
813
|
-
this._onended();
|
|
814
|
-
};
|
|
815
|
-
startTime = time ? AbstractEngine.audioEngine?.audioContext.currentTime + time : AbstractEngine.audioEngine.audioContext.currentTime;
|
|
816
|
-
const actualOffset = ((this.isPaused ? this.currentTime : 0) + (this._offset ?? 0)) % this._soundSource.buffer.duration;
|
|
817
|
-
this._soundSource.start(startTime, actualOffset, this.loop ? undefined : length);
|
|
818
|
-
}
|
|
819
|
-
}
|
|
820
|
-
};
|
|
821
|
-
if (AbstractEngine.audioEngine?.audioContext.state === "suspended") {
|
|
822
|
-
// Wait a bit for FF as context seems late to be ready.
|
|
823
|
-
this._tryToPlayTimeout = setTimeout(() => {
|
|
824
|
-
if (AbstractEngine.audioEngine?.audioContext.state === "suspended") {
|
|
825
|
-
// Automatic playback failed.
|
|
826
|
-
// Waiting for the audio engine to be unlocked by user click on unmute
|
|
827
|
-
AbstractEngine.audioEngine.lock();
|
|
828
|
-
if (this.loop || this.autoplay) {
|
|
829
|
-
this._audioUnlockedObserver = AbstractEngine.audioEngine.onAudioUnlockedObservable.addOnce(() => {
|
|
830
|
-
tryToPlay();
|
|
831
|
-
});
|
|
832
|
-
}
|
|
833
|
-
}
|
|
834
|
-
else {
|
|
835
|
-
tryToPlay();
|
|
836
|
-
}
|
|
837
|
-
}, 500);
|
|
838
|
-
}
|
|
839
|
-
else {
|
|
840
|
-
tryToPlay();
|
|
841
|
-
}
|
|
842
|
-
}
|
|
843
|
-
this._startTime = startTime;
|
|
844
|
-
this.isPlaying = true;
|
|
845
|
-
this.isPaused = false;
|
|
846
|
-
}
|
|
847
|
-
catch (ex) {
|
|
848
|
-
Logger.Error("Error while trying to play audio: " + this.name + ", " + ex.message);
|
|
849
|
-
}
|
|
850
|
-
}
|
|
851
|
-
}
|
|
852
|
-
_onended() {
|
|
853
|
-
this.isPlaying = false;
|
|
854
|
-
this._startTime = 0;
|
|
855
|
-
this._currentTime = 0;
|
|
856
|
-
if (this.onended) {
|
|
857
|
-
this.onended();
|
|
858
|
-
}
|
|
859
|
-
this.onEndedObservable.notifyObservers(this);
|
|
860
|
-
}
|
|
861
|
-
/**
|
|
862
|
-
* Stop the sound
|
|
863
|
-
* @param time (optional) Stop the sound after X seconds. Stop immediately (0) by default.
|
|
864
|
-
*/
|
|
865
|
-
stop(time) {
|
|
866
|
-
if (this.isPlaying) {
|
|
867
|
-
this._clearTimeoutsAndObservers();
|
|
868
|
-
if (this._streaming) {
|
|
869
|
-
if (this._htmlAudioElement) {
|
|
870
|
-
this._htmlAudioElement.pause();
|
|
871
|
-
// Test needed for Firefox or it will generate an Invalid State Error
|
|
872
|
-
if (this._htmlAudioElement.currentTime > 0) {
|
|
873
|
-
this._htmlAudioElement.currentTime = 0;
|
|
874
|
-
}
|
|
875
|
-
}
|
|
876
|
-
else {
|
|
877
|
-
this._streamingSource.disconnect();
|
|
878
|
-
}
|
|
879
|
-
this.isPlaying = false;
|
|
880
|
-
}
|
|
881
|
-
else if (AbstractEngine.audioEngine?.audioContext && this._soundSource) {
|
|
882
|
-
const stopTime = time ? AbstractEngine.audioEngine.audioContext.currentTime + time : undefined;
|
|
883
|
-
this._soundSource.onended = () => {
|
|
884
|
-
this.isPlaying = false;
|
|
885
|
-
this.isPaused = false;
|
|
886
|
-
this._startTime = 0;
|
|
887
|
-
this._currentTime = 0;
|
|
888
|
-
if (this._soundSource) {
|
|
889
|
-
this._soundSource.onended = () => void 0;
|
|
890
|
-
}
|
|
891
|
-
this._onended();
|
|
892
|
-
};
|
|
893
|
-
this._soundSource.stop(stopTime);
|
|
894
|
-
}
|
|
895
|
-
else {
|
|
896
|
-
this.isPlaying = false;
|
|
897
|
-
}
|
|
898
|
-
}
|
|
899
|
-
else if (this.isPaused) {
|
|
900
|
-
this.isPaused = false;
|
|
901
|
-
this._startTime = 0;
|
|
902
|
-
this._currentTime = 0;
|
|
903
|
-
}
|
|
904
|
-
}
|
|
905
|
-
/**
|
|
906
|
-
* Put the sound in pause
|
|
907
|
-
*/
|
|
908
|
-
pause() {
|
|
909
|
-
if (this.isPlaying) {
|
|
910
|
-
this._clearTimeoutsAndObservers();
|
|
911
|
-
if (this._streaming) {
|
|
912
|
-
if (this._htmlAudioElement) {
|
|
913
|
-
this._htmlAudioElement.pause();
|
|
914
|
-
}
|
|
915
|
-
else {
|
|
916
|
-
this._streamingSource.disconnect();
|
|
917
|
-
}
|
|
918
|
-
this.isPlaying = false;
|
|
919
|
-
this.isPaused = true;
|
|
920
|
-
}
|
|
921
|
-
else if (AbstractEngine.audioEngine?.audioContext && this._soundSource) {
|
|
922
|
-
this._soundSource.onended = () => void 0;
|
|
923
|
-
this._soundSource.stop();
|
|
924
|
-
this.isPlaying = false;
|
|
925
|
-
this.isPaused = true;
|
|
926
|
-
this._currentTime += AbstractEngine.audioEngine.audioContext.currentTime - this._startTime;
|
|
927
|
-
}
|
|
928
|
-
}
|
|
929
|
-
}
|
|
930
|
-
/**
|
|
931
|
-
* Sets a dedicated volume for this sounds
|
|
932
|
-
* @param newVolume Define the new volume of the sound
|
|
933
|
-
* @param time Define time for gradual change to new volume
|
|
934
|
-
*/
|
|
935
|
-
setVolume(newVolume, time) {
|
|
936
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && this._soundGain) {
|
|
937
|
-
if (time && AbstractEngine.audioEngine.audioContext) {
|
|
938
|
-
this._soundGain.gain.cancelScheduledValues(AbstractEngine.audioEngine.audioContext.currentTime);
|
|
939
|
-
this._soundGain.gain.setValueAtTime(this._soundGain.gain.value, AbstractEngine.audioEngine.audioContext.currentTime);
|
|
940
|
-
this._soundGain.gain.linearRampToValueAtTime(newVolume, AbstractEngine.audioEngine.audioContext.currentTime + time);
|
|
941
|
-
}
|
|
942
|
-
else {
|
|
943
|
-
this._soundGain.gain.value = newVolume;
|
|
944
|
-
}
|
|
945
|
-
}
|
|
946
|
-
this._volume = newVolume;
|
|
947
|
-
}
|
|
948
|
-
/**
|
|
949
|
-
* Set the sound play back rate
|
|
950
|
-
* @param newPlaybackRate Define the playback rate the sound should be played at
|
|
951
|
-
*/
|
|
952
|
-
setPlaybackRate(newPlaybackRate) {
|
|
953
|
-
this._playbackRate = newPlaybackRate;
|
|
954
|
-
if (this.isPlaying) {
|
|
955
|
-
if (this._streaming && this._htmlAudioElement) {
|
|
956
|
-
this._htmlAudioElement.playbackRate = this._playbackRate;
|
|
957
|
-
}
|
|
958
|
-
else if (this._soundSource) {
|
|
959
|
-
this._soundSource.playbackRate.value = this._playbackRate;
|
|
960
|
-
}
|
|
961
|
-
}
|
|
962
|
-
}
|
|
963
|
-
/**
|
|
964
|
-
* Gets the sound play back rate.
|
|
965
|
-
* @returns the play back rate of the sound
|
|
966
|
-
*/
|
|
967
|
-
getPlaybackRate() {
|
|
968
|
-
return this._playbackRate;
|
|
969
|
-
}
|
|
970
|
-
/**
|
|
971
|
-
* Gets the volume of the sound.
|
|
972
|
-
* @returns the volume of the sound
|
|
973
|
-
*/
|
|
974
|
-
getVolume() {
|
|
975
|
-
return this._volume;
|
|
976
|
-
}
|
|
977
|
-
/**
|
|
978
|
-
* Attach the sound to a dedicated mesh
|
|
979
|
-
* @param transformNode The transform node to connect the sound with
|
|
980
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#attaching-a-sound-to-a-mesh
|
|
981
|
-
*/
|
|
982
|
-
attachToMesh(transformNode) {
|
|
983
|
-
if (this._connectedTransformNode && this._registerFunc) {
|
|
984
|
-
this._connectedTransformNode.unregisterAfterWorldMatrixUpdate(this._registerFunc);
|
|
985
|
-
this._registerFunc = null;
|
|
986
|
-
}
|
|
987
|
-
this._connectedTransformNode = transformNode;
|
|
988
|
-
if (!this._spatialSound) {
|
|
989
|
-
this._spatialSound = true;
|
|
990
|
-
this._createSpatialParameters();
|
|
991
|
-
if (this.isPlaying && this.loop) {
|
|
992
|
-
this.stop();
|
|
993
|
-
this.play(0, this._offset, this._length);
|
|
994
|
-
}
|
|
995
|
-
}
|
|
996
|
-
this._onRegisterAfterWorldMatrixUpdate(this._connectedTransformNode);
|
|
997
|
-
this._registerFunc = (transformNode) => this._onRegisterAfterWorldMatrixUpdate(transformNode);
|
|
998
|
-
this._connectedTransformNode.registerAfterWorldMatrixUpdate(this._registerFunc);
|
|
999
|
-
}
|
|
1000
|
-
/**
|
|
1001
|
-
* Detach the sound from the previously attached mesh
|
|
1002
|
-
* @see https://doc.babylonjs.com/features/featuresDeepDive/audio/playingSoundsMusic#attaching-a-sound-to-a-mesh
|
|
1003
|
-
*/
|
|
1004
|
-
detachFromMesh() {
|
|
1005
|
-
if (this._connectedTransformNode && this._registerFunc) {
|
|
1006
|
-
this._connectedTransformNode.unregisterAfterWorldMatrixUpdate(this._registerFunc);
|
|
1007
|
-
this._registerFunc = null;
|
|
1008
|
-
this._connectedTransformNode = null;
|
|
1009
|
-
}
|
|
1010
|
-
}
|
|
1011
|
-
_onRegisterAfterWorldMatrixUpdate(node) {
|
|
1012
|
-
if (!node.getBoundingInfo) {
|
|
1013
|
-
this.setPosition(node.absolutePosition);
|
|
1014
|
-
}
|
|
1015
|
-
else {
|
|
1016
|
-
const mesh = node;
|
|
1017
|
-
const boundingInfo = mesh.getBoundingInfo();
|
|
1018
|
-
this.setPosition(boundingInfo.boundingSphere.centerWorld);
|
|
1019
|
-
}
|
|
1020
|
-
if (AbstractEngine.audioEngine?.canUseWebAudio && this._isDirectional && this.isPlaying) {
|
|
1021
|
-
this._updateDirection();
|
|
1022
|
-
}
|
|
1023
|
-
}
|
|
1024
|
-
/**
|
|
1025
|
-
* Clone the current sound in the scene.
|
|
1026
|
-
* @returns the new sound clone
|
|
1027
|
-
*/
|
|
1028
|
-
clone() {
|
|
1029
|
-
if (!this._streaming) {
|
|
1030
|
-
const setBufferAndRun = () => {
|
|
1031
|
-
if (this._isReadyToPlay) {
|
|
1032
|
-
clonedSound._audioBuffer = this.getAudioBuffer();
|
|
1033
|
-
clonedSound._isReadyToPlay = true;
|
|
1034
|
-
if (clonedSound.autoplay) {
|
|
1035
|
-
clonedSound.play(0, this._offset, this._length);
|
|
1036
|
-
}
|
|
1037
|
-
}
|
|
1038
|
-
else {
|
|
1039
|
-
setTimeout(setBufferAndRun, 300);
|
|
1040
|
-
}
|
|
1041
|
-
};
|
|
1042
|
-
const currentOptions = {
|
|
1043
|
-
autoplay: this.autoplay,
|
|
1044
|
-
loop: this.loop,
|
|
1045
|
-
volume: this._volume,
|
|
1046
|
-
spatialSound: this._spatialSound,
|
|
1047
|
-
maxDistance: this.maxDistance,
|
|
1048
|
-
useCustomAttenuation: this.useCustomAttenuation,
|
|
1049
|
-
rolloffFactor: this.rolloffFactor,
|
|
1050
|
-
refDistance: this.refDistance,
|
|
1051
|
-
distanceModel: this.distanceModel,
|
|
1052
|
-
};
|
|
1053
|
-
const clonedSound = new Sound(this.name + "_cloned", new ArrayBuffer(0), this._scene, null, currentOptions);
|
|
1054
|
-
if (this.useCustomAttenuation) {
|
|
1055
|
-
clonedSound.setAttenuationFunction(this._customAttenuationFunction);
|
|
1056
|
-
}
|
|
1057
|
-
clonedSound.setPosition(this._position);
|
|
1058
|
-
clonedSound.setPlaybackRate(this._playbackRate);
|
|
1059
|
-
setBufferAndRun();
|
|
1060
|
-
return clonedSound;
|
|
1061
|
-
}
|
|
1062
|
-
// Can't clone a streaming sound
|
|
1063
|
-
else {
|
|
1064
|
-
return null;
|
|
1065
|
-
}
|
|
1066
|
-
}
|
|
1067
|
-
/**
|
|
1068
|
-
* Gets the current underlying audio buffer containing the data
|
|
1069
|
-
* @returns the audio buffer
|
|
1070
|
-
*/
|
|
1071
|
-
getAudioBuffer() {
|
|
1072
|
-
return this._audioBuffer;
|
|
1073
|
-
}
|
|
1074
|
-
/**
|
|
1075
|
-
* Gets the WebAudio AudioBufferSourceNode, lets you keep track of and stop instances of this Sound.
|
|
1076
|
-
* @returns the source node
|
|
1077
|
-
*/
|
|
1078
|
-
getSoundSource() {
|
|
1079
|
-
return this._soundSource;
|
|
1080
|
-
}
|
|
1081
|
-
/**
|
|
1082
|
-
* Gets the WebAudio GainNode, gives you precise control over the gain of instances of this Sound.
|
|
1083
|
-
* @returns the gain node
|
|
1084
|
-
*/
|
|
1085
|
-
getSoundGain() {
|
|
1086
|
-
return this._soundGain;
|
|
1087
|
-
}
|
|
1088
|
-
/**
|
|
1089
|
-
* Serializes the Sound in a JSON representation
|
|
1090
|
-
* @returns the JSON representation of the sound
|
|
1091
|
-
*/
|
|
1092
|
-
serialize() {
|
|
1093
|
-
const serializationObject = {
|
|
1094
|
-
name: this.name,
|
|
1095
|
-
url: this._url,
|
|
1096
|
-
autoplay: this.autoplay,
|
|
1097
|
-
loop: this.loop,
|
|
1098
|
-
volume: this._volume,
|
|
1099
|
-
spatialSound: this._spatialSound,
|
|
1100
|
-
maxDistance: this.maxDistance,
|
|
1101
|
-
rolloffFactor: this.rolloffFactor,
|
|
1102
|
-
refDistance: this.refDistance,
|
|
1103
|
-
distanceModel: this.distanceModel,
|
|
1104
|
-
playbackRate: this._playbackRate,
|
|
1105
|
-
panningModel: this._panningModel,
|
|
1106
|
-
soundTrackId: this.soundTrackId,
|
|
1107
|
-
metadata: this.metadata,
|
|
1108
|
-
};
|
|
1109
|
-
if (this._spatialSound) {
|
|
1110
|
-
if (this._connectedTransformNode) {
|
|
1111
|
-
serializationObject.connectedMeshId = this._connectedTransformNode.id;
|
|
1112
|
-
}
|
|
1113
|
-
serializationObject.position = this._position.asArray();
|
|
1114
|
-
serializationObject.refDistance = this.refDistance;
|
|
1115
|
-
serializationObject.distanceModel = this.distanceModel;
|
|
1116
|
-
serializationObject.isDirectional = this._isDirectional;
|
|
1117
|
-
serializationObject.localDirectionToMesh = this._localDirection.asArray();
|
|
1118
|
-
serializationObject.coneInnerAngle = this._coneInnerAngle;
|
|
1119
|
-
serializationObject.coneOuterAngle = this._coneOuterAngle;
|
|
1120
|
-
serializationObject.coneOuterGain = this._coneOuterGain;
|
|
1121
|
-
}
|
|
1122
|
-
return serializationObject;
|
|
1123
|
-
}
|
|
1124
|
-
/**
|
|
1125
|
-
* Parse a JSON representation of a sound to instantiate in a given scene
|
|
1126
|
-
* @param parsedSound Define the JSON representation of the sound (usually coming from the serialize method)
|
|
1127
|
-
* @param scene Define the scene the new parsed sound should be created in
|
|
1128
|
-
* @param rootUrl Define the rooturl of the load in case we need to fetch relative dependencies
|
|
1129
|
-
* @param sourceSound Define a sound place holder if do not need to instantiate a new one
|
|
1130
|
-
* @returns the newly parsed sound
|
|
1131
|
-
*/
|
|
1132
|
-
static Parse(parsedSound, scene, rootUrl, sourceSound) {
|
|
1133
|
-
const soundName = parsedSound.name;
|
|
1134
|
-
let soundUrl;
|
|
1135
|
-
if (parsedSound.url) {
|
|
1136
|
-
soundUrl = rootUrl + parsedSound.url;
|
|
1137
|
-
}
|
|
1138
|
-
else {
|
|
1139
|
-
soundUrl = rootUrl + soundName;
|
|
1140
|
-
}
|
|
1141
|
-
const options = {
|
|
1142
|
-
autoplay: parsedSound.autoplay,
|
|
1143
|
-
loop: parsedSound.loop,
|
|
1144
|
-
volume: parsedSound.volume,
|
|
1145
|
-
spatialSound: parsedSound.spatialSound,
|
|
1146
|
-
maxDistance: parsedSound.maxDistance,
|
|
1147
|
-
rolloffFactor: parsedSound.rolloffFactor,
|
|
1148
|
-
refDistance: parsedSound.refDistance,
|
|
1149
|
-
distanceModel: parsedSound.distanceModel,
|
|
1150
|
-
playbackRate: parsedSound.playbackRate,
|
|
1151
|
-
};
|
|
1152
|
-
let newSound;
|
|
1153
|
-
if (!sourceSound) {
|
|
1154
|
-
newSound = new Sound(soundName, soundUrl, scene, () => {
|
|
1155
|
-
scene.removePendingData(newSound);
|
|
1156
|
-
}, options);
|
|
1157
|
-
scene.addPendingData(newSound);
|
|
1158
|
-
}
|
|
1159
|
-
else {
|
|
1160
|
-
const setBufferAndRun = () => {
|
|
1161
|
-
if (sourceSound._isReadyToPlay) {
|
|
1162
|
-
newSound._audioBuffer = sourceSound.getAudioBuffer();
|
|
1163
|
-
newSound._isReadyToPlay = true;
|
|
1164
|
-
if (newSound.autoplay) {
|
|
1165
|
-
newSound.play(0, newSound._offset, newSound._length);
|
|
1166
|
-
}
|
|
1167
|
-
}
|
|
1168
|
-
else {
|
|
1169
|
-
setTimeout(setBufferAndRun, 300);
|
|
1170
|
-
}
|
|
1171
|
-
};
|
|
1172
|
-
newSound = new Sound(soundName, new ArrayBuffer(0), scene, null, options);
|
|
1173
|
-
setBufferAndRun();
|
|
1174
|
-
}
|
|
1175
|
-
if (parsedSound.position) {
|
|
1176
|
-
const soundPosition = Vector3.FromArray(parsedSound.position);
|
|
1177
|
-
newSound.setPosition(soundPosition);
|
|
1178
|
-
}
|
|
1179
|
-
if (parsedSound.isDirectional) {
|
|
1180
|
-
newSound.setDirectionalCone(parsedSound.coneInnerAngle || 360, parsedSound.coneOuterAngle || 360, parsedSound.coneOuterGain || 0);
|
|
1181
|
-
if (parsedSound.localDirectionToMesh) {
|
|
1182
|
-
const localDirectionToMesh = Vector3.FromArray(parsedSound.localDirectionToMesh);
|
|
1183
|
-
newSound.setLocalDirectionToMesh(localDirectionToMesh);
|
|
1184
|
-
}
|
|
1185
|
-
}
|
|
1186
|
-
if (parsedSound.connectedMeshId) {
|
|
1187
|
-
const connectedMesh = scene.getMeshById(parsedSound.connectedMeshId);
|
|
1188
|
-
if (connectedMesh) {
|
|
1189
|
-
newSound.attachToMesh(connectedMesh);
|
|
1190
|
-
}
|
|
1191
|
-
}
|
|
1192
|
-
if (parsedSound.metadata) {
|
|
1193
|
-
newSound.metadata = parsedSound.metadata;
|
|
1194
|
-
}
|
|
1195
|
-
return newSound;
|
|
1196
|
-
}
|
|
1197
|
-
_setOffset(value) {
|
|
1198
|
-
if (this._offset === value) {
|
|
1199
|
-
return;
|
|
1200
|
-
}
|
|
1201
|
-
if (this.isPaused) {
|
|
1202
|
-
this.stop();
|
|
1203
|
-
this.isPaused = false;
|
|
1204
|
-
}
|
|
1205
|
-
this._offset = value;
|
|
1206
|
-
}
|
|
1207
|
-
_clearTimeoutsAndObservers() {
|
|
1208
|
-
if (this._tryToPlayTimeout) {
|
|
1209
|
-
clearTimeout(this._tryToPlayTimeout);
|
|
1210
|
-
this._tryToPlayTimeout = null;
|
|
1211
|
-
}
|
|
1212
|
-
if (this._audioUnlockedObserver) {
|
|
1213
|
-
AbstractEngine.audioEngine?.onAudioUnlockedObservable.remove(this._audioUnlockedObserver);
|
|
1214
|
-
this._audioUnlockedObserver = null;
|
|
1215
|
-
}
|
|
1216
|
-
}
|
|
1217
|
-
}
|
|
1218
|
-
/**
|
|
1219
|
-
* @internal
|
|
1220
|
-
*/
|
|
1221
|
-
Sound._SceneComponentInitialization = (_) => {
|
|
1222
|
-
throw _WarnImport("AudioSceneComponent");
|
|
1223
|
-
};
|
|
1224
|
-
// Register Class Name
|
|
1225
|
-
RegisterClass("BABYLON.Sound", Sound);
|
|
1226
|
-
|
|
1227
|
-
/**
|
|
1228
|
-
* Wraps one or more Sound objects and selects one with random weight for playback.
|
|
1229
|
-
*/
|
|
1230
|
-
class WeightedSound {
|
|
1231
|
-
/**
|
|
1232
|
-
* Creates a new WeightedSound from the list of sounds given.
|
|
1233
|
-
* @param loop When true a Sound will be selected and played when the current playing Sound completes.
|
|
1234
|
-
* @param sounds Array of Sounds that will be selected from.
|
|
1235
|
-
* @param weights Array of number values for selection weights; length must equal sounds, values will be normalized to 1
|
|
1236
|
-
*/
|
|
1237
|
-
constructor(loop, sounds, weights) {
|
|
1238
|
-
/** When true a Sound will be selected and played when the current playing Sound completes. */
|
|
1239
|
-
this.loop = false;
|
|
1240
|
-
this._coneInnerAngle = 360;
|
|
1241
|
-
this._coneOuterAngle = 360;
|
|
1242
|
-
this._volume = 1;
|
|
1243
|
-
/** A Sound is currently playing. */
|
|
1244
|
-
this.isPlaying = false;
|
|
1245
|
-
/** A Sound is currently paused. */
|
|
1246
|
-
this.isPaused = false;
|
|
1247
|
-
this._sounds = [];
|
|
1248
|
-
this._weights = [];
|
|
1249
|
-
if (sounds.length !== weights.length) {
|
|
1250
|
-
throw new Error("Sounds length does not equal weights length");
|
|
1251
|
-
}
|
|
1252
|
-
this.loop = loop;
|
|
1253
|
-
this._weights = weights;
|
|
1254
|
-
// Normalize the weights
|
|
1255
|
-
let weightSum = 0;
|
|
1256
|
-
for (const weight of weights) {
|
|
1257
|
-
weightSum += weight;
|
|
1258
|
-
}
|
|
1259
|
-
const invWeightSum = weightSum > 0 ? 1 / weightSum : 0;
|
|
1260
|
-
for (let i = 0; i < this._weights.length; i++) {
|
|
1261
|
-
this._weights[i] *= invWeightSum;
|
|
1262
|
-
}
|
|
1263
|
-
this._sounds = sounds;
|
|
1264
|
-
for (const sound of this._sounds) {
|
|
1265
|
-
sound.onEndedObservable.add(() => {
|
|
1266
|
-
this._onended();
|
|
1267
|
-
});
|
|
1268
|
-
}
|
|
1269
|
-
}
|
|
1270
|
-
/**
|
|
1271
|
-
* The size of cone in degrees for a directional sound in which there will be no attenuation.
|
|
1272
|
-
*/
|
|
1273
|
-
get directionalConeInnerAngle() {
|
|
1274
|
-
return this._coneInnerAngle;
|
|
1275
|
-
}
|
|
1276
|
-
/**
|
|
1277
|
-
* The size of cone in degrees for a directional sound in which there will be no attenuation.
|
|
1278
|
-
*/
|
|
1279
|
-
set directionalConeInnerAngle(value) {
|
|
1280
|
-
if (value !== this._coneInnerAngle) {
|
|
1281
|
-
if (this._coneOuterAngle < value) {
|
|
1282
|
-
Logger.Error("directionalConeInnerAngle: outer angle of the cone must be superior or equal to the inner angle.");
|
|
1283
|
-
return;
|
|
1284
|
-
}
|
|
1285
|
-
this._coneInnerAngle = value;
|
|
1286
|
-
for (const sound of this._sounds) {
|
|
1287
|
-
sound.directionalConeInnerAngle = value;
|
|
1288
|
-
}
|
|
1289
|
-
}
|
|
1290
|
-
}
|
|
1291
|
-
/**
|
|
1292
|
-
* Size of cone in degrees for a directional sound outside of which there will be no sound.
|
|
1293
|
-
* Listener angles between innerAngle and outerAngle will falloff linearly.
|
|
1294
|
-
*/
|
|
1295
|
-
get directionalConeOuterAngle() {
|
|
1296
|
-
return this._coneOuterAngle;
|
|
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
|
-
set directionalConeOuterAngle(value) {
|
|
1303
|
-
if (value !== this._coneOuterAngle) {
|
|
1304
|
-
if (value < this._coneInnerAngle) {
|
|
1305
|
-
Logger.Error("directionalConeOuterAngle: outer angle of the cone must be superior or equal to the inner angle.");
|
|
1306
|
-
return;
|
|
1307
|
-
}
|
|
1308
|
-
this._coneOuterAngle = value;
|
|
1309
|
-
for (const sound of this._sounds) {
|
|
1310
|
-
sound.directionalConeOuterAngle = value;
|
|
1311
|
-
}
|
|
1312
|
-
}
|
|
1313
|
-
}
|
|
1314
|
-
/**
|
|
1315
|
-
* Playback volume.
|
|
1316
|
-
*/
|
|
1317
|
-
get volume() {
|
|
1318
|
-
return this._volume;
|
|
1319
|
-
}
|
|
1320
|
-
/**
|
|
1321
|
-
* Playback volume.
|
|
1322
|
-
*/
|
|
1323
|
-
set volume(value) {
|
|
1324
|
-
if (value !== this._volume) {
|
|
1325
|
-
for (const sound of this._sounds) {
|
|
1326
|
-
sound.setVolume(value);
|
|
1327
|
-
}
|
|
1328
|
-
}
|
|
1329
|
-
}
|
|
1330
|
-
_onended() {
|
|
1331
|
-
if (this._currentIndex !== undefined) {
|
|
1332
|
-
this._sounds[this._currentIndex].autoplay = false;
|
|
1333
|
-
}
|
|
1334
|
-
if (this.loop && this.isPlaying) {
|
|
1335
|
-
this.play();
|
|
1336
|
-
}
|
|
1337
|
-
else {
|
|
1338
|
-
this.isPlaying = false;
|
|
1339
|
-
}
|
|
1340
|
-
}
|
|
1341
|
-
/**
|
|
1342
|
-
* Suspend playback
|
|
1343
|
-
*/
|
|
1344
|
-
pause() {
|
|
1345
|
-
this.isPaused = true;
|
|
1346
|
-
if (this._currentIndex !== undefined) {
|
|
1347
|
-
this._sounds[this._currentIndex].pause();
|
|
1348
|
-
}
|
|
1349
|
-
}
|
|
1350
|
-
/**
|
|
1351
|
-
* Stop playback
|
|
1352
|
-
*/
|
|
1353
|
-
stop() {
|
|
1354
|
-
this.isPlaying = false;
|
|
1355
|
-
if (this._currentIndex !== undefined) {
|
|
1356
|
-
this._sounds[this._currentIndex].stop();
|
|
1357
|
-
}
|
|
1358
|
-
}
|
|
1359
|
-
/**
|
|
1360
|
-
* Start playback.
|
|
1361
|
-
* @param startOffset Position the clip head at a specific time in seconds.
|
|
1362
|
-
*/
|
|
1363
|
-
play(startOffset) {
|
|
1364
|
-
if (!this.isPaused) {
|
|
1365
|
-
this.stop();
|
|
1366
|
-
const randomValue = Math.random();
|
|
1367
|
-
let total = 0;
|
|
1368
|
-
for (let i = 0; i < this._weights.length; i++) {
|
|
1369
|
-
total += this._weights[i];
|
|
1370
|
-
if (randomValue <= total) {
|
|
1371
|
-
this._currentIndex = i;
|
|
1372
|
-
break;
|
|
1373
|
-
}
|
|
1374
|
-
}
|
|
1375
|
-
}
|
|
1376
|
-
const sound = this._sounds[this._currentIndex];
|
|
1377
|
-
if (sound.isReady()) {
|
|
1378
|
-
sound.play(0, this.isPaused ? undefined : startOffset);
|
|
1379
|
-
}
|
|
1380
|
-
else {
|
|
1381
|
-
sound.autoplay = true;
|
|
1382
|
-
}
|
|
1383
|
-
this.isPlaying = true;
|
|
1384
|
-
this.isPaused = false;
|
|
1385
|
-
}
|
|
1386
|
-
}
|
|
1387
|
-
|
|
1388
|
-
const NAME = "MSFT_audio_emitter";
|
|
1389
|
-
/**
|
|
1390
|
-
* [Specification](https://github.com/najadojo/glTF/blob/MSFT_audio_emitter/extensions/2.0/Vendor/MSFT_audio_emitter/README.md)
|
|
1391
|
-
* !!! Experimental Extension Subject to Changes !!!
|
|
1392
|
-
*/
|
|
1393
|
-
// eslint-disable-next-line @typescript-eslint/naming-convention
|
|
1394
|
-
class MSFT_audio_emitter {
|
|
1395
|
-
/**
|
|
1396
|
-
* @internal
|
|
1397
|
-
*/
|
|
1398
|
-
constructor(loader) {
|
|
1399
|
-
/**
|
|
1400
|
-
* The name of this extension.
|
|
1401
|
-
*/
|
|
1402
|
-
this.name = NAME;
|
|
1403
|
-
this._loader = loader;
|
|
1404
|
-
this.enabled = this._loader.isExtensionUsed(NAME);
|
|
1405
|
-
}
|
|
1406
|
-
/** @internal */
|
|
1407
|
-
dispose() {
|
|
1408
|
-
this._loader = null;
|
|
1409
|
-
this._clips = null;
|
|
1410
|
-
this._emitters = null;
|
|
1411
|
-
}
|
|
1412
|
-
/** @internal */
|
|
1413
|
-
onLoading() {
|
|
1414
|
-
const extensions = this._loader.gltf.extensions;
|
|
1415
|
-
if (extensions && extensions[this.name]) {
|
|
1416
|
-
const extension = extensions[this.name];
|
|
1417
|
-
this._clips = extension.clips;
|
|
1418
|
-
this._emitters = extension.emitters;
|
|
1419
|
-
ArrayItem.Assign(this._clips);
|
|
1420
|
-
ArrayItem.Assign(this._emitters);
|
|
1421
|
-
}
|
|
1422
|
-
}
|
|
1423
|
-
/**
|
|
1424
|
-
* @internal
|
|
1425
|
-
*/
|
|
1426
|
-
loadSceneAsync(context, scene) {
|
|
1427
|
-
return GLTFLoader.LoadExtensionAsync(context, scene, this.name, (extensionContext, extension) => {
|
|
1428
|
-
const promises = new Array();
|
|
1429
|
-
promises.push(this._loader.loadSceneAsync(context, scene));
|
|
1430
|
-
for (const emitterIndex of extension.emitters) {
|
|
1431
|
-
const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);
|
|
1432
|
-
if (emitter.refDistance != undefined ||
|
|
1433
|
-
emitter.maxDistance != undefined ||
|
|
1434
|
-
emitter.rolloffFactor != undefined ||
|
|
1435
|
-
emitter.distanceModel != undefined ||
|
|
1436
|
-
emitter.innerAngle != undefined ||
|
|
1437
|
-
emitter.outerAngle != undefined) {
|
|
1438
|
-
throw new Error(`${extensionContext}: Direction or Distance properties are not allowed on emitters attached to a scene`);
|
|
1439
|
-
}
|
|
1440
|
-
promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter));
|
|
1441
|
-
}
|
|
1442
|
-
return Promise.all(promises).then(() => { });
|
|
1443
|
-
});
|
|
1444
|
-
}
|
|
1445
|
-
/**
|
|
1446
|
-
* @internal
|
|
1447
|
-
*/
|
|
1448
|
-
loadNodeAsync(context, node, assign) {
|
|
1449
|
-
return GLTFLoader.LoadExtensionAsync(context, node, this.name, (extensionContext, extension) => {
|
|
1450
|
-
const promises = new Array();
|
|
1451
|
-
return this._loader
|
|
1452
|
-
.loadNodeAsync(extensionContext, node, (babylonMesh) => {
|
|
1453
|
-
for (const emitterIndex of extension.emitters) {
|
|
1454
|
-
const emitter = ArrayItem.Get(`${extensionContext}/emitters`, this._emitters, emitterIndex);
|
|
1455
|
-
promises.push(this._loadEmitterAsync(`${extensionContext}/emitters/${emitter.index}`, emitter).then(() => {
|
|
1456
|
-
for (const sound of emitter._babylonSounds) {
|
|
1457
|
-
sound.attachToMesh(babylonMesh);
|
|
1458
|
-
if (emitter.innerAngle != undefined || emitter.outerAngle != undefined) {
|
|
1459
|
-
sound.setLocalDirectionToMesh(Vector3.Forward());
|
|
1460
|
-
sound.setDirectionalCone(2 * Tools.ToDegrees(emitter.innerAngle == undefined ? Math.PI : emitter.innerAngle), 2 * Tools.ToDegrees(emitter.outerAngle == undefined ? Math.PI : emitter.outerAngle), 0);
|
|
1461
|
-
}
|
|
1462
|
-
}
|
|
1463
|
-
}));
|
|
1464
|
-
}
|
|
1465
|
-
assign(babylonMesh);
|
|
1466
|
-
})
|
|
1467
|
-
.then((babylonMesh) => {
|
|
1468
|
-
return Promise.all(promises).then(() => {
|
|
1469
|
-
return babylonMesh;
|
|
1470
|
-
});
|
|
1471
|
-
});
|
|
1472
|
-
});
|
|
1473
|
-
}
|
|
1474
|
-
/**
|
|
1475
|
-
* @internal
|
|
1476
|
-
*/
|
|
1477
|
-
loadAnimationAsync(context, animation) {
|
|
1478
|
-
return GLTFLoader.LoadExtensionAsync(context, animation, this.name, (extensionContext, extension) => {
|
|
1479
|
-
return this._loader.loadAnimationAsync(context, animation).then((babylonAnimationGroup) => {
|
|
1480
|
-
const promises = new Array();
|
|
1481
|
-
ArrayItem.Assign(extension.events);
|
|
1482
|
-
for (const event of extension.events) {
|
|
1483
|
-
promises.push(this._loadAnimationEventAsync(`${extensionContext}/events/${event.index}`, context, animation, event, babylonAnimationGroup));
|
|
1484
|
-
}
|
|
1485
|
-
return Promise.all(promises).then(() => {
|
|
1486
|
-
return babylonAnimationGroup;
|
|
1487
|
-
});
|
|
1488
|
-
});
|
|
1489
|
-
});
|
|
1490
|
-
}
|
|
1491
|
-
_loadClipAsync(context, clip) {
|
|
1492
|
-
if (clip._objectURL) {
|
|
1493
|
-
return clip._objectURL;
|
|
1494
|
-
}
|
|
1495
|
-
let promise;
|
|
1496
|
-
if (clip.uri) {
|
|
1497
|
-
promise = this._loader.loadUriAsync(context, clip, clip.uri);
|
|
1498
|
-
}
|
|
1499
|
-
else {
|
|
1500
|
-
const bufferView = ArrayItem.Get(`${context}/bufferView`, this._loader.gltf.bufferViews, clip.bufferView);
|
|
1501
|
-
promise = this._loader.loadBufferViewAsync(`/bufferViews/${bufferView.index}`, bufferView);
|
|
1502
|
-
}
|
|
1503
|
-
clip._objectURL = promise.then((data) => {
|
|
1504
|
-
return URL.createObjectURL(new Blob([data], { type: clip.mimeType }));
|
|
1505
|
-
});
|
|
1506
|
-
return clip._objectURL;
|
|
1507
|
-
}
|
|
1508
|
-
_loadEmitterAsync(context, emitter) {
|
|
1509
|
-
emitter._babylonSounds = emitter._babylonSounds || [];
|
|
1510
|
-
if (!emitter._babylonData) {
|
|
1511
|
-
const clipPromises = new Array();
|
|
1512
|
-
const name = emitter.name || `emitter${emitter.index}`;
|
|
1513
|
-
const options = {
|
|
1514
|
-
loop: false,
|
|
1515
|
-
autoplay: false,
|
|
1516
|
-
volume: emitter.volume == undefined ? 1 : emitter.volume,
|
|
1517
|
-
};
|
|
1518
|
-
for (let i = 0; i < emitter.clips.length; i++) {
|
|
1519
|
-
const clipContext = `/extensions/${this.name}/clips`;
|
|
1520
|
-
const clip = ArrayItem.Get(clipContext, this._clips, emitter.clips[i].clip);
|
|
1521
|
-
clipPromises.push(this._loadClipAsync(`${clipContext}/${emitter.clips[i].clip}`, clip).then((objectURL) => {
|
|
1522
|
-
const sound = (emitter._babylonSounds[i] = new Sound(name, objectURL, this._loader.babylonScene, null, options));
|
|
1523
|
-
sound.refDistance = emitter.refDistance || 1;
|
|
1524
|
-
sound.maxDistance = emitter.maxDistance || 256;
|
|
1525
|
-
sound.rolloffFactor = emitter.rolloffFactor || 1;
|
|
1526
|
-
sound.distanceModel = emitter.distanceModel || "exponential";
|
|
1527
|
-
}));
|
|
1528
|
-
}
|
|
1529
|
-
const promise = Promise.all(clipPromises).then(() => {
|
|
1530
|
-
const weights = emitter.clips.map((clip) => {
|
|
1531
|
-
return clip.weight || 1;
|
|
1532
|
-
});
|
|
1533
|
-
const weightedSound = new WeightedSound(emitter.loop || false, emitter._babylonSounds, weights);
|
|
1534
|
-
if (emitter.innerAngle) {
|
|
1535
|
-
weightedSound.directionalConeInnerAngle = 2 * Tools.ToDegrees(emitter.innerAngle);
|
|
1536
|
-
}
|
|
1537
|
-
if (emitter.outerAngle) {
|
|
1538
|
-
weightedSound.directionalConeOuterAngle = 2 * Tools.ToDegrees(emitter.outerAngle);
|
|
1539
|
-
}
|
|
1540
|
-
if (emitter.volume) {
|
|
1541
|
-
weightedSound.volume = emitter.volume;
|
|
1542
|
-
}
|
|
1543
|
-
emitter._babylonData.sound = weightedSound;
|
|
1544
|
-
});
|
|
1545
|
-
emitter._babylonData = {
|
|
1546
|
-
loaded: promise,
|
|
1547
|
-
};
|
|
1548
|
-
}
|
|
1549
|
-
return emitter._babylonData.loaded;
|
|
1550
|
-
}
|
|
1551
|
-
_getEventAction(context, sound, action, time, startOffset) {
|
|
1552
|
-
switch (action) {
|
|
1553
|
-
case "play" /* IMSFTAudioEmitter_AnimationEventAction.play */: {
|
|
1554
|
-
return (currentFrame) => {
|
|
1555
|
-
const frameOffset = (startOffset || 0) + (currentFrame - time);
|
|
1556
|
-
sound.play(frameOffset);
|
|
1557
|
-
};
|
|
1558
|
-
}
|
|
1559
|
-
case "stop" /* IMSFTAudioEmitter_AnimationEventAction.stop */: {
|
|
1560
|
-
return () => {
|
|
1561
|
-
sound.stop();
|
|
1562
|
-
};
|
|
1563
|
-
}
|
|
1564
|
-
case "pause" /* IMSFTAudioEmitter_AnimationEventAction.pause */: {
|
|
1565
|
-
return () => {
|
|
1566
|
-
sound.pause();
|
|
1567
|
-
};
|
|
1568
|
-
}
|
|
1569
|
-
default: {
|
|
1570
|
-
throw new Error(`${context}: Unsupported action ${action}`);
|
|
1571
|
-
}
|
|
1572
|
-
}
|
|
1573
|
-
}
|
|
1574
|
-
_loadAnimationEventAsync(context, animationContext, animation, event, babylonAnimationGroup) {
|
|
1575
|
-
if (babylonAnimationGroup.targetedAnimations.length == 0) {
|
|
1576
|
-
return Promise.resolve();
|
|
1577
|
-
}
|
|
1578
|
-
const babylonAnimation = babylonAnimationGroup.targetedAnimations[0];
|
|
1579
|
-
const emitterIndex = event.emitter;
|
|
1580
|
-
const emitter = ArrayItem.Get(`/extensions/${this.name}/emitters`, this._emitters, emitterIndex);
|
|
1581
|
-
return this._loadEmitterAsync(context, emitter).then(() => {
|
|
1582
|
-
const sound = emitter._babylonData.sound;
|
|
1583
|
-
if (sound) {
|
|
1584
|
-
const babylonAnimationEvent = new AnimationEvent(event.time, this._getEventAction(context, sound, event.action, event.time, event.startOffset));
|
|
1585
|
-
babylonAnimation.animation.addEvent(babylonAnimationEvent);
|
|
1586
|
-
// Make sure all started audio stops when this animation is terminated.
|
|
1587
|
-
babylonAnimationGroup.onAnimationGroupEndObservable.add(() => {
|
|
1588
|
-
sound.stop();
|
|
1589
|
-
});
|
|
1590
|
-
babylonAnimationGroup.onAnimationGroupPauseObservable.add(() => {
|
|
1591
|
-
sound.pause();
|
|
1592
|
-
});
|
|
1593
|
-
}
|
|
1594
|
-
});
|
|
1595
|
-
}
|
|
1596
|
-
}
|
|
1597
|
-
unregisterGLTFExtension(NAME);
|
|
1598
|
-
registerGLTFExtension(NAME, true, (loader) => new MSFT_audio_emitter(loader));
|
|
1599
|
-
|
|
1600
|
-
export { MSFT_audio_emitter };
|
|
1601
|
-
//# sourceMappingURL=MSFT_audio_emitter-CANraFUR.esm.js.map
|