@babylonjs/core 7.21.4 → 7.22.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/Audio/analyser.js +3 -3
- package/Audio/analyser.js.map +1 -1
- package/Audio/audioSceneComponent.js +7 -7
- package/Audio/audioSceneComponent.js.map +1 -1
- package/Audio/sound.js +55 -50
- package/Audio/sound.js.map +1 -1
- package/Audio/soundTrack.js +11 -11
- package/Audio/soundTrack.js.map +1 -1
- package/Cameras/flyCamera.js +2 -2
- package/Cameras/flyCamera.js.map +1 -1
- package/Cameras/freeCamera.js +2 -2
- package/Cameras/freeCamera.js.map +1 -1
- package/Collisions/collisionCoordinator.js +2 -2
- package/Collisions/collisionCoordinator.js.map +1 -1
- package/Debug/debugLayer.js +2 -2
- package/Debug/debugLayer.js.map +1 -1
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.js +25 -28
- package/Engines/AbstractEngine/abstractEngine.cubeTexture.js.map +1 -1
- package/Engines/abstractEngine.d.ts +18 -3
- package/Engines/abstractEngine.js +32 -13
- package/Engines/abstractEngine.js.map +1 -1
- package/Engines/engine.d.ts +0 -7
- package/Engines/engine.js +0 -13
- package/Engines/engine.js.map +1 -1
- package/Engines/nativeEngine.js +3 -9
- package/Engines/nativeEngine.js.map +1 -1
- package/Engines/thinEngine.d.ts +0 -37
- package/Engines/thinEngine.js +2 -40
- package/Engines/thinEngine.js.map +1 -1
- package/Engines/webgpuEngine.js +1 -2
- package/Engines/webgpuEngine.js.map +1 -1
- package/Gamepads/gamepadManager.js +2 -2
- package/Gamepads/gamepadManager.js.map +1 -1
- package/Loading/sceneLoader.d.ts +2 -2
- package/Loading/sceneLoader.js +3 -3
- package/Loading/sceneLoader.js.map +1 -1
- package/Materials/Node/nodeMaterialBuildState.d.ts +3 -3
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.d.ts +31 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.d.ts +9 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.js +454 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.huf.js.map +1 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.js +147 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.js.map +1 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.rle.d.ts +7 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.rle.js +91 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.compression.rle.js.map +1 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.configuration.d.ts +17 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.configuration.js +19 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.configuration.js.map +1 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.core.d.ts +130 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.core.js +452 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.core.js.map +1 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.decoder.d.ts +25 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.decoder.js +284 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.decoder.js.map +1 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.header.d.ts +9 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.header.js +112 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.header.js.map +1 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.interfaces.d.ts +75 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.interfaces.js +16 -0
- package/Materials/Textures/Loaders/EXR/exrLoader.interfaces.js.map +1 -0
- package/Materials/Textures/Loaders/EXR/index.d.ts +7 -0
- package/Materials/Textures/Loaders/EXR/index.js +8 -0
- package/Materials/Textures/Loaders/EXR/index.js.map +1 -0
- package/Materials/Textures/Loaders/basisTextureLoader.d.ts +1 -7
- package/Materials/Textures/Loaders/basisTextureLoader.js +0 -11
- package/Materials/Textures/Loaders/basisTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/ddsTextureLoader.d.ts +1 -7
- package/Materials/Textures/Loaders/ddsTextureLoader.js +0 -11
- package/Materials/Textures/Loaders/ddsTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/envTextureLoader.d.ts +1 -7
- package/Materials/Textures/Loaders/envTextureLoader.js +0 -11
- package/Materials/Textures/Loaders/envTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/exrTextureLoader.d.ts +37 -0
- package/Materials/Textures/Loaders/exrTextureLoader.js +122 -0
- package/Materials/Textures/Loaders/exrTextureLoader.js.map +1 -0
- package/Materials/Textures/Loaders/hdrTextureLoader.d.ts +1 -7
- package/Materials/Textures/Loaders/hdrTextureLoader.js +0 -11
- package/Materials/Textures/Loaders/hdrTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/index.d.ts +4 -0
- package/Materials/Textures/Loaders/index.js +5 -0
- package/Materials/Textures/Loaders/index.js.map +1 -1
- package/Materials/Textures/{internalTextureLoader.d.ts → Loaders/internalTextureLoader.d.ts} +2 -9
- package/Materials/Textures/Loaders/internalTextureLoader.js.map +1 -0
- package/Materials/Textures/Loaders/ktxTextureLoader.d.ts +1 -8
- package/Materials/Textures/Loaders/ktxTextureLoader.js +0 -13
- package/Materials/Textures/Loaders/ktxTextureLoader.js.map +1 -1
- package/Materials/Textures/Loaders/textureLoaderManager.d.ts +9 -0
- package/Materials/Textures/Loaders/textureLoaderManager.js +32 -0
- package/Materials/Textures/Loaders/textureLoaderManager.js.map +1 -0
- package/Materials/Textures/Loaders/tgaTextureLoader.d.ts +1 -7
- package/Materials/Textures/Loaders/tgaTextureLoader.js +0 -11
- package/Materials/Textures/Loaders/tgaTextureLoader.js.map +1 -1
- package/Materials/Textures/Packer/packer.js +2 -2
- package/Materials/Textures/Packer/packer.js.map +1 -1
- package/Materials/Textures/index.d.ts +0 -1
- package/Materials/Textures/index.js +0 -1
- package/Materials/Textures/index.js.map +1 -1
- package/Materials/fresnelParameters.js +2 -2
- package/Materials/fresnelParameters.js.map +1 -1
- package/Materials/materialFlags.js +24 -24
- package/Materials/materialFlags.js.map +1 -1
- package/Meshes/Node/nodeGeometry.js +2 -2
- package/Meshes/Node/nodeGeometry.js.map +1 -1
- package/Meshes/abstractMesh.js +2 -2
- package/Meshes/abstractMesh.js.map +1 -1
- package/Misc/fileTools.d.ts +13 -0
- package/Misc/fileTools.js +16 -0
- package/Misc/fileTools.js.map +1 -1
- package/Offline/database.js +2 -2
- package/Offline/database.js.map +1 -1
- package/Rendering/boundingBoxRenderer.d.ts +2 -2
- package/Rendering/boundingBoxRenderer.js +2 -2
- package/Rendering/boundingBoxRenderer.js.map +1 -1
- package/Rendering/edgesRenderer.d.ts +7 -2
- package/Rendering/edgesRenderer.js +23 -6
- package/Rendering/edgesRenderer.js.map +1 -1
- package/Rendering/index.d.ts +12 -4
- package/Rendering/index.js +14 -4
- package/Rendering/index.js.map +1 -1
- package/Rendering/outlineRenderer.d.ts +7 -2
- package/Rendering/outlineRenderer.js +64 -11
- package/Rendering/outlineRenderer.js.map +1 -1
- package/ShadersWGSL/line.fragment.d.ts +9 -0
- package/ShadersWGSL/line.fragment.js +24 -0
- package/ShadersWGSL/line.fragment.js.map +1 -0
- package/ShadersWGSL/line.vertex.d.ts +13 -0
- package/ShadersWGSL/line.vertex.js +36 -0
- package/ShadersWGSL/line.vertex.js.map +1 -0
- package/ShadersWGSL/outline.fragment.d.ts +9 -0
- package/ShadersWGSL/outline.fragment.js +30 -0
- package/ShadersWGSL/outline.fragment.js.map +1 -0
- package/ShadersWGSL/outline.vertex.d.ts +19 -0
- package/ShadersWGSL/outline.vertex.js +66 -0
- package/ShadersWGSL/outline.vertex.js.map +1 -0
- package/Sprites/spriteMap.js +4 -4
- package/Sprites/spriteMap.js.map +1 -1
- package/XR/features/WebXRDepthSensing.js +2 -3
- package/XR/features/WebXRDepthSensing.js.map +1 -1
- package/XR/webXRExperienceHelper.js +2 -2
- package/XR/webXRExperienceHelper.js.map +1 -1
- package/package.json +1 -1
- package/scene.js +2 -3
- package/scene.js.map +1 -1
- package/Materials/Textures/internalTextureLoader.js.map +0 -1
- /package/Materials/Textures/{internalTextureLoader.js → Loaders/internalTextureLoader.js} +0 -0
package/Audio/sound.js
CHANGED
|
@@ -1,11 +1,11 @@
|
|
|
1
1
|
import { Tools } from "../Misc/tools.js";
|
|
2
2
|
import { Observable } from "../Misc/observable.js";
|
|
3
3
|
import { Vector3 } from "../Maths/math.vector.js";
|
|
4
|
-
import { Engine } from "../Engines/engine.js";
|
|
5
4
|
import { Logger } from "../Misc/logger.js";
|
|
6
5
|
import { _WarnImport } from "../Misc/devTools.js";
|
|
7
6
|
import { EngineStore } from "../Engines/engineStore.js";
|
|
8
7
|
import { RegisterClass } from "../Misc/typeStore.js";
|
|
8
|
+
import { AbstractEngine } from "../Engines/abstractEngine.js";
|
|
9
9
|
/**
|
|
10
10
|
* Defines a sound that can be played in the application.
|
|
11
11
|
* The sound can either be an ambient track or a simple sound played in reaction to a user action.
|
|
@@ -32,10 +32,10 @@ export class Sound {
|
|
|
32
32
|
if (this._htmlAudioElement) {
|
|
33
33
|
return this._htmlAudioElement.currentTime;
|
|
34
34
|
}
|
|
35
|
-
if (
|
|
35
|
+
if (AbstractEngine.audioEngine?.audioContext && (this.isPlaying || this.isPaused)) {
|
|
36
36
|
// The `_currentTime` member is only updated when the sound is paused. Add the time since the last start
|
|
37
37
|
// to get the actual current time.
|
|
38
|
-
const timeSinceLastStart = this.isPaused ? 0 :
|
|
38
|
+
const timeSinceLastStart = this.isPaused ? 0 : AbstractEngine.audioEngine.audioContext.currentTime - this._startTime;
|
|
39
39
|
return this._currentTime + timeSinceLastStart;
|
|
40
40
|
}
|
|
41
41
|
return 0;
|
|
@@ -178,8 +178,8 @@ export class Sound {
|
|
|
178
178
|
this._length = options.length;
|
|
179
179
|
this._offset = options.offset;
|
|
180
180
|
}
|
|
181
|
-
if (
|
|
182
|
-
this._soundGain =
|
|
181
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && AbstractEngine.audioEngine.audioContext) {
|
|
182
|
+
this._soundGain = AbstractEngine.audioEngine.audioContext.createGain();
|
|
183
183
|
this._soundGain.gain.value = this._volume;
|
|
184
184
|
this._inputAudioNode = this._soundGain;
|
|
185
185
|
this._outputAudioNode = this._soundGain;
|
|
@@ -216,7 +216,7 @@ export class Sound {
|
|
|
216
216
|
case "MediaElement":
|
|
217
217
|
this._streaming = true;
|
|
218
218
|
this._isReadyToPlay = true;
|
|
219
|
-
this._streamingSource =
|
|
219
|
+
this._streamingSource = AbstractEngine.audioEngine.audioContext.createMediaElementSource(urlOrArrayBuffer);
|
|
220
220
|
if (this.autoplay) {
|
|
221
221
|
this.play(0, this._offset, this._length);
|
|
222
222
|
}
|
|
@@ -227,7 +227,7 @@ export class Sound {
|
|
|
227
227
|
case "MediaStream":
|
|
228
228
|
this._streaming = true;
|
|
229
229
|
this._isReadyToPlay = true;
|
|
230
|
-
this._streamingSource =
|
|
230
|
+
this._streamingSource = AbstractEngine.audioEngine.audioContext.createMediaStreamSource(urlOrArrayBuffer);
|
|
231
231
|
if (this.autoplay) {
|
|
232
232
|
this.play(0, this._offset, this._length);
|
|
233
233
|
}
|
|
@@ -256,8 +256,8 @@ export class Sound {
|
|
|
256
256
|
const url = urls[i];
|
|
257
257
|
codecSupportedFound =
|
|
258
258
|
(options && options.skipCodecCheck) ||
|
|
259
|
-
(url.indexOf(".mp3", url.length - 4) !== -1 &&
|
|
260
|
-
(url.indexOf(".ogg", url.length - 4) !== -1 &&
|
|
259
|
+
(url.indexOf(".mp3", url.length - 4) !== -1 && AbstractEngine.audioEngine.isMP3supported) ||
|
|
260
|
+
(url.indexOf(".ogg", url.length - 4) !== -1 && AbstractEngine.audioEngine.isOGGsupported) ||
|
|
261
261
|
url.indexOf(".wav", url.length - 4) !== -1 ||
|
|
262
262
|
url.indexOf(".m4a", url.length - 4) !== -1 ||
|
|
263
263
|
url.indexOf(".mp4", url.length - 4) !== -1 ||
|
|
@@ -328,9 +328,9 @@ export class Sound {
|
|
|
328
328
|
else {
|
|
329
329
|
// Adding an empty sound to avoid breaking audio calls for non Web Audio browsers
|
|
330
330
|
this._scene.mainSoundTrack.addSound(this);
|
|
331
|
-
if (
|
|
331
|
+
if (AbstractEngine.audioEngine && !AbstractEngine.audioEngine.WarnedWebAudioUnsupported) {
|
|
332
332
|
Logger.Error("Web Audio is not supported by your browser.");
|
|
333
|
-
|
|
333
|
+
AbstractEngine.audioEngine.WarnedWebAudioUnsupported = true;
|
|
334
334
|
}
|
|
335
335
|
// Simulating a ready to play event to avoid breaking code for non web audio browsers
|
|
336
336
|
if (this._readyToPlayCallback) {
|
|
@@ -346,7 +346,7 @@ export class Sound {
|
|
|
346
346
|
* Release the sound and its associated resources
|
|
347
347
|
*/
|
|
348
348
|
dispose() {
|
|
349
|
-
if (
|
|
349
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio) {
|
|
350
350
|
if (this.isPlaying) {
|
|
351
351
|
this.stop();
|
|
352
352
|
}
|
|
@@ -400,7 +400,7 @@ export class Sound {
|
|
|
400
400
|
return "Sound";
|
|
401
401
|
}
|
|
402
402
|
_audioBufferLoaded(buffer) {
|
|
403
|
-
if (!
|
|
403
|
+
if (!AbstractEngine.audioEngine?.audioContext) {
|
|
404
404
|
return;
|
|
405
405
|
}
|
|
406
406
|
this._audioBuffer = buffer;
|
|
@@ -413,10 +413,10 @@ export class Sound {
|
|
|
413
413
|
}
|
|
414
414
|
}
|
|
415
415
|
_soundLoaded(audioData) {
|
|
416
|
-
if (!
|
|
416
|
+
if (!AbstractEngine.audioEngine?.audioContext) {
|
|
417
417
|
return;
|
|
418
418
|
}
|
|
419
|
-
|
|
419
|
+
AbstractEngine.audioEngine.audioContext.decodeAudioData(audioData, (buffer) => {
|
|
420
420
|
this._audioBufferLoaded(buffer);
|
|
421
421
|
}, (err) => {
|
|
422
422
|
Logger.Error("Error while decoding audio data for: " + this.name + " / Error: " + err);
|
|
@@ -427,7 +427,7 @@ export class Sound {
|
|
|
427
427
|
* @param audioBuffer The audioBuffer containing the data
|
|
428
428
|
*/
|
|
429
429
|
setAudioBuffer(audioBuffer) {
|
|
430
|
-
if (
|
|
430
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio) {
|
|
431
431
|
this._audioBuffer = audioBuffer;
|
|
432
432
|
this._isReadyToPlay = true;
|
|
433
433
|
}
|
|
@@ -475,11 +475,11 @@ export class Sound {
|
|
|
475
475
|
}
|
|
476
476
|
}
|
|
477
477
|
_createSpatialParameters() {
|
|
478
|
-
if (
|
|
478
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && AbstractEngine.audioEngine.audioContext) {
|
|
479
479
|
if (this._scene.headphone) {
|
|
480
480
|
this._panningModel = "HRTF";
|
|
481
481
|
}
|
|
482
|
-
this._soundPanner = this._soundPanner ??
|
|
482
|
+
this._soundPanner = this._soundPanner ?? AbstractEngine.audioEngine.audioContext.createPanner();
|
|
483
483
|
if (this._soundPanner && this._outputAudioNode) {
|
|
484
484
|
this._updateSpatialParameters();
|
|
485
485
|
this._soundPanner.connect(this._outputAudioNode);
|
|
@@ -540,7 +540,7 @@ export class Sound {
|
|
|
540
540
|
this._switchPanningModel();
|
|
541
541
|
}
|
|
542
542
|
_switchPanningModel() {
|
|
543
|
-
if (
|
|
543
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
|
|
544
544
|
this._soundPanner.panningModel = this._panningModel;
|
|
545
545
|
}
|
|
546
546
|
}
|
|
@@ -549,7 +549,7 @@ export class Sound {
|
|
|
549
549
|
* @param soundTrackAudioNode the sound track audio node to connect to
|
|
550
550
|
*/
|
|
551
551
|
connectToSoundTrackAudioNode(soundTrackAudioNode) {
|
|
552
|
-
if (
|
|
552
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && this._outputAudioNode) {
|
|
553
553
|
if (this._isOutputConnected) {
|
|
554
554
|
this._outputAudioNode.disconnect();
|
|
555
555
|
}
|
|
@@ -593,7 +593,7 @@ export class Sound {
|
|
|
593
593
|
return;
|
|
594
594
|
}
|
|
595
595
|
this._coneInnerAngle = value;
|
|
596
|
-
if (
|
|
596
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
|
|
597
597
|
this._soundPanner.coneInnerAngle = this._coneInnerAngle;
|
|
598
598
|
}
|
|
599
599
|
}
|
|
@@ -614,7 +614,7 @@ export class Sound {
|
|
|
614
614
|
return;
|
|
615
615
|
}
|
|
616
616
|
this._coneOuterAngle = value;
|
|
617
|
-
if (
|
|
617
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && this._spatialSound && this._soundPanner) {
|
|
618
618
|
this._soundPanner.coneOuterAngle = this._coneOuterAngle;
|
|
619
619
|
}
|
|
620
620
|
}
|
|
@@ -628,7 +628,12 @@ export class Sound {
|
|
|
628
628
|
return;
|
|
629
629
|
}
|
|
630
630
|
this._position.copyFrom(newPosition);
|
|
631
|
-
if (
|
|
631
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio &&
|
|
632
|
+
this._spatialSound &&
|
|
633
|
+
this._soundPanner &&
|
|
634
|
+
!isNaN(this._position.x) &&
|
|
635
|
+
!isNaN(this._position.y) &&
|
|
636
|
+
!isNaN(this._position.z)) {
|
|
632
637
|
this._soundPanner.positionX.value = this._position.x;
|
|
633
638
|
this._soundPanner.positionY.value = this._position.y;
|
|
634
639
|
this._soundPanner.positionZ.value = this._position.z;
|
|
@@ -640,7 +645,7 @@ export class Sound {
|
|
|
640
645
|
*/
|
|
641
646
|
setLocalDirectionToMesh(newLocalDirection) {
|
|
642
647
|
this._localDirection = newLocalDirection;
|
|
643
|
-
if (
|
|
648
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && this._connectedTransformNode && this.isPlaying) {
|
|
644
649
|
this._updateDirection();
|
|
645
650
|
}
|
|
646
651
|
}
|
|
@@ -657,7 +662,7 @@ export class Sound {
|
|
|
657
662
|
}
|
|
658
663
|
/** @internal */
|
|
659
664
|
updateDistanceFromListener() {
|
|
660
|
-
if (
|
|
665
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && this._connectedTransformNode && this.useCustomAttenuation && this._soundGain && this._scene.activeCamera) {
|
|
661
666
|
const distance = this._scene.audioListenerPositionProvider
|
|
662
667
|
? this._connectedTransformNode.position.subtract(this._scene.audioListenerPositionProvider()).length()
|
|
663
668
|
: this._connectedTransformNode.getDistanceToCamera(this._scene.activeCamera);
|
|
@@ -679,10 +684,10 @@ export class Sound {
|
|
|
679
684
|
* @param length (optional) Sound duration (in seconds)
|
|
680
685
|
*/
|
|
681
686
|
play(time, offset, length) {
|
|
682
|
-
if (this._isReadyToPlay && this._scene.audioEnabled &&
|
|
687
|
+
if (this._isReadyToPlay && this._scene.audioEnabled && AbstractEngine.audioEngine?.audioContext) {
|
|
683
688
|
try {
|
|
684
689
|
this._clearTimeoutsAndObservers();
|
|
685
|
-
let startTime = time ?
|
|
690
|
+
let startTime = time ? AbstractEngine.audioEngine?.audioContext.currentTime + time : AbstractEngine.audioEngine?.audioContext.currentTime;
|
|
686
691
|
if (!this._soundSource || !this._streamingSource) {
|
|
687
692
|
if (this._spatialSound && this._soundPanner) {
|
|
688
693
|
if (!isNaN(this._position.x) && !isNaN(this._position.y) && !isNaN(this._position.z)) {
|
|
@@ -705,7 +710,7 @@ export class Sound {
|
|
|
705
710
|
}
|
|
706
711
|
if (this._streaming) {
|
|
707
712
|
if (!this._streamingSource) {
|
|
708
|
-
this._streamingSource =
|
|
713
|
+
this._streamingSource = AbstractEngine.audioEngine.audioContext.createMediaElementSource(this._htmlAudioElement);
|
|
709
714
|
this._htmlAudioElement.onended = () => {
|
|
710
715
|
this._onended();
|
|
711
716
|
};
|
|
@@ -721,7 +726,7 @@ export class Sound {
|
|
|
721
726
|
// the audio engine to be unlocked by a user gesture before trying to play
|
|
722
727
|
// an HTML Audio element
|
|
723
728
|
const tryToPlay = () => {
|
|
724
|
-
if (
|
|
729
|
+
if (AbstractEngine.audioEngine?.unlocked) {
|
|
725
730
|
const playPromise = this._htmlAudioElement.play();
|
|
726
731
|
// In browsers that don’t yet support this functionality,
|
|
727
732
|
// playPromise won’t be defined.
|
|
@@ -729,9 +734,9 @@ export class Sound {
|
|
|
729
734
|
playPromise.catch(() => {
|
|
730
735
|
// Automatic playback failed.
|
|
731
736
|
// Waiting for the audio engine to be unlocked by user click on unmute
|
|
732
|
-
|
|
737
|
+
AbstractEngine.audioEngine?.lock();
|
|
733
738
|
if (this.loop || this.autoplay) {
|
|
734
|
-
this._audioUnlockedObserver =
|
|
739
|
+
this._audioUnlockedObserver = AbstractEngine.audioEngine?.onAudioUnlockedObservable.addOnce(() => {
|
|
735
740
|
tryToPlay();
|
|
736
741
|
});
|
|
737
742
|
}
|
|
@@ -740,7 +745,7 @@ export class Sound {
|
|
|
740
745
|
}
|
|
741
746
|
else {
|
|
742
747
|
if (this.loop || this.autoplay) {
|
|
743
|
-
this._audioUnlockedObserver =
|
|
748
|
+
this._audioUnlockedObserver = AbstractEngine.audioEngine?.onAudioUnlockedObservable.addOnce(() => {
|
|
744
749
|
tryToPlay();
|
|
745
750
|
});
|
|
746
751
|
}
|
|
@@ -751,7 +756,7 @@ export class Sound {
|
|
|
751
756
|
}
|
|
752
757
|
else {
|
|
753
758
|
const tryToPlay = () => {
|
|
754
|
-
if (
|
|
759
|
+
if (AbstractEngine.audioEngine?.audioContext) {
|
|
755
760
|
length = length || this._length;
|
|
756
761
|
if (offset !== undefined) {
|
|
757
762
|
this._setOffset(offset);
|
|
@@ -762,7 +767,7 @@ export class Sound {
|
|
|
762
767
|
oldSource.disconnect();
|
|
763
768
|
};
|
|
764
769
|
}
|
|
765
|
-
this._soundSource =
|
|
770
|
+
this._soundSource = AbstractEngine.audioEngine?.audioContext.createBufferSource();
|
|
766
771
|
if (this._soundSource && this._inputAudioNode) {
|
|
767
772
|
this._soundSource.buffer = this._audioBuffer;
|
|
768
773
|
this._soundSource.connect(this._inputAudioNode);
|
|
@@ -777,21 +782,21 @@ export class Sound {
|
|
|
777
782
|
this._soundSource.onended = () => {
|
|
778
783
|
this._onended();
|
|
779
784
|
};
|
|
780
|
-
startTime = time ?
|
|
785
|
+
startTime = time ? AbstractEngine.audioEngine?.audioContext.currentTime + time : AbstractEngine.audioEngine.audioContext.currentTime;
|
|
781
786
|
const actualOffset = ((this.isPaused ? this.currentTime : 0) + (this._offset ?? 0)) % this._soundSource.buffer.duration;
|
|
782
787
|
this._soundSource.start(startTime, actualOffset, this.loop ? undefined : length);
|
|
783
788
|
}
|
|
784
789
|
}
|
|
785
790
|
};
|
|
786
|
-
if (
|
|
791
|
+
if (AbstractEngine.audioEngine?.audioContext.state === "suspended") {
|
|
787
792
|
// Wait a bit for FF as context seems late to be ready.
|
|
788
793
|
this._tryToPlayTimeout = setTimeout(() => {
|
|
789
|
-
if (
|
|
794
|
+
if (AbstractEngine.audioEngine?.audioContext.state === "suspended") {
|
|
790
795
|
// Automatic playback failed.
|
|
791
796
|
// Waiting for the audio engine to be unlocked by user click on unmute
|
|
792
|
-
|
|
797
|
+
AbstractEngine.audioEngine.lock();
|
|
793
798
|
if (this.loop || this.autoplay) {
|
|
794
|
-
this._audioUnlockedObserver =
|
|
799
|
+
this._audioUnlockedObserver = AbstractEngine.audioEngine.onAudioUnlockedObservable.addOnce(() => {
|
|
795
800
|
tryToPlay();
|
|
796
801
|
});
|
|
797
802
|
}
|
|
@@ -843,8 +848,8 @@ export class Sound {
|
|
|
843
848
|
}
|
|
844
849
|
this.isPlaying = false;
|
|
845
850
|
}
|
|
846
|
-
else if (
|
|
847
|
-
const stopTime = time ?
|
|
851
|
+
else if (AbstractEngine.audioEngine?.audioContext && this._soundSource) {
|
|
852
|
+
const stopTime = time ? AbstractEngine.audioEngine.audioContext.currentTime + time : undefined;
|
|
848
853
|
this._soundSource.onended = () => {
|
|
849
854
|
this.isPlaying = false;
|
|
850
855
|
this.isPaused = false;
|
|
@@ -883,12 +888,12 @@ export class Sound {
|
|
|
883
888
|
this.isPlaying = false;
|
|
884
889
|
this.isPaused = true;
|
|
885
890
|
}
|
|
886
|
-
else if (
|
|
891
|
+
else if (AbstractEngine.audioEngine?.audioContext && this._soundSource) {
|
|
887
892
|
this._soundSource.onended = () => void 0;
|
|
888
893
|
this._soundSource.stop();
|
|
889
894
|
this.isPlaying = false;
|
|
890
895
|
this.isPaused = true;
|
|
891
|
-
this._currentTime +=
|
|
896
|
+
this._currentTime += AbstractEngine.audioEngine.audioContext.currentTime - this._startTime;
|
|
892
897
|
}
|
|
893
898
|
}
|
|
894
899
|
}
|
|
@@ -898,11 +903,11 @@ export class Sound {
|
|
|
898
903
|
* @param time Define time for gradual change to new volume
|
|
899
904
|
*/
|
|
900
905
|
setVolume(newVolume, time) {
|
|
901
|
-
if (
|
|
902
|
-
if (time &&
|
|
903
|
-
this._soundGain.gain.cancelScheduledValues(
|
|
904
|
-
this._soundGain.gain.setValueAtTime(this._soundGain.gain.value,
|
|
905
|
-
this._soundGain.gain.linearRampToValueAtTime(newVolume,
|
|
906
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && this._soundGain) {
|
|
907
|
+
if (time && AbstractEngine.audioEngine.audioContext) {
|
|
908
|
+
this._soundGain.gain.cancelScheduledValues(AbstractEngine.audioEngine.audioContext.currentTime);
|
|
909
|
+
this._soundGain.gain.setValueAtTime(this._soundGain.gain.value, AbstractEngine.audioEngine.audioContext.currentTime);
|
|
910
|
+
this._soundGain.gain.linearRampToValueAtTime(newVolume, AbstractEngine.audioEngine.audioContext.currentTime + time);
|
|
906
911
|
}
|
|
907
912
|
else {
|
|
908
913
|
this._soundGain.gain.value = newVolume;
|
|
@@ -982,7 +987,7 @@ export class Sound {
|
|
|
982
987
|
const boundingInfo = mesh.getBoundingInfo();
|
|
983
988
|
this.setPosition(boundingInfo.boundingSphere.centerWorld);
|
|
984
989
|
}
|
|
985
|
-
if (
|
|
990
|
+
if (AbstractEngine.audioEngine?.canUseWebAudio && this._isDirectional && this.isPlaying) {
|
|
986
991
|
this._updateDirection();
|
|
987
992
|
}
|
|
988
993
|
}
|
|
@@ -1175,7 +1180,7 @@ export class Sound {
|
|
|
1175
1180
|
this._tryToPlayTimeout = null;
|
|
1176
1181
|
}
|
|
1177
1182
|
if (this._audioUnlockedObserver) {
|
|
1178
|
-
|
|
1183
|
+
AbstractEngine.audioEngine?.onAudioUnlockedObservable.remove(this._audioUnlockedObserver);
|
|
1179
1184
|
this._audioUnlockedObserver = null;
|
|
1180
1185
|
}
|
|
1181
1186
|
}
|