@babylonjs/lite-compat 1.3.0-preview → 1.6.0-preview

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/index.js CHANGED
@@ -1,9 +1,9 @@
1
1
  var __defProp = Object.defineProperty;
2
2
  var __defNormalProp = (obj, key, value) => key in obj ? __defProp(obj, key, { enumerable: true, configurable: true, writable: true, value }) : obj[key] = value;
3
3
  var __publicField = (obj, key, value) => __defNormalProp(obj, typeof key !== "symbol" ? key + "" : key, value);
4
- import { V as Vector3, u as unsupported, L as LiteCompatError, N as Node, M as Matrix, a as Mesh, T as TransformNode, l as liteBackedVector3 } from "./meshes-BkNs_oK5.js";
5
- import { A, C, b, c, d, e, f, g, G, I, h, Q, i, j, k, m, t, n } from "./meshes-BkNs_oK5.js";
6
- import { createEngine, onBeforeRender, stopEngine, resizeEngine, setEngineSize, disposeEngine, registerSceneWithShadowSupport, registerScene, startEngine, createArcRotateCamera, attachControl, getCameraPosition, getViewMatrix, getProjectionMatrix, createGeospatialCamera, setGeospatialOrientation, attachGeospatialControls, createFreeCamera, attachFreeControl, markMaterialUboDirty, createPbrMaterial, createSolidTexture2D, createStandardMaterial, setAnimationAdditive, playAnimation, pauseAnimation, goToFrame, stopAnimation, createSceneContext, updateAnimationManager, setFog, setClipPlane, loadDdsEnvironment, loadEnvironment, createDefaultCamera, addToScene, createHemisphericLight, createAnimationManager, enableAnimationBlending, addAnimationGroup, disposeScene, createDirectionalLight, createPointLight, createSpotLight, createCsgFromMesh, csgSubtract, csgIntersect, csgUnion, createMeshFromCsg, createCsg2FromMesh, csg2Subtract, csg2Intersect, csg2Add, createMeshesFromCsg2, disposeCsg2, initializeCsg2Async, createMorphTargets, setMorphTargetWeights, createTransformNode, bakeCurrentTransformIntoVertices, loadSOG, loadSPZ, loadSplat, createTexture2DFromPixels, updateTexture2DFromPixels, loadBasisTexture2D, loadKtxTexture2D, loadTexture2D, getContainerMeshes, loadBabylon, loadGltf, resetVariant, getVariantNames, selectVariant, disposePicker, createGpuPicker, pickAsync, createAxisDragGizmo, attachAxisDragGizmoToNode, disposeAxisDragGizmo, createAxisScaleGizmo, attachAxisScaleGizmoToNode, disposeAxisScaleGizmo, createBoundingBoxGizmo, attachBoundingBoxGizmoToNode, disposeBoundingBoxGizmo, createCameraGizmo, attachCameraGizmoToCamera, disposeCameraGizmo, createLightGizmo, attachLightGizmoToLight, disposeLightGizmo, createPlaneDragGizmo, attachPlaneDragGizmoToNode, disposePlaneDragGizmo, createPlaneRotationGizmo, attachPlaneRotationGizmoToNode, disposePlaneRotationGizmo, createPositionGizmo, setPositionGizmoLocalCoordinates, attachPositionGizmoToNode, disposePositionGizmo, createRotationGizmo, setRotationGizmoLocalCoordinates, attachRotationGizmoToNode, disposeRotationGizmo, createScaleGizmo, setScaleGizmoLocalCoordinates, attachScaleGizmoToNode, disposeScaleGizmo, createUtilityLayer, registerUtilityLayer, disposeUtilityLayer, addBillboardSpriteIndex, updateBillboardSpriteIndex, loadSpriteAtlas, createFacingBillboardSystem, addFacingBillboardSystem, billboardBlendAdditive, billboardBlendAlpha, spriteBlendPremultiplied, spriteBlendAdditive, spriteBlendAlpha, createSprite2DLayer, addSprite2DIndex, createSpriteRenderer, registerSpriteRenderer, updateSprite2DIndex, createPcfSpotlightShadowGenerator, createPcfDirectionalShadowGenerator, createEsmDirectionalShadowGenerator, setShadowTaskCasterMeshes, parseNodeMaterialFromSnippet, createGridMaterial } from "@babylonjs/lite";
4
+ import { V as Vector3, u as unsupported, L as LiteCompatError, N as Node, M as Matrix, a as Mesh, T as TransformNode, l as liteBackedVector3, Q as Quaternion } from "./meshes-a59_KvbH.js";
5
+ import { A, C, b, c, d, e, f, g, G, I, h, i, j, k, m, t, n } from "./meshes-a59_KvbH.js";
6
+ import { createEngine, onBeforeRender, stopEngine, resizeEngine, setEngineSize, disposeEngine, registerSceneWithShadowSupport, registerScene, startEngine, createArcRotateCamera, attachControl, getCameraPosition, getViewMatrix, getProjectionMatrix, createGeospatialCamera, setGeospatialOrientation, attachGeospatialControls, createFreeCamera, attachFreeControl, markMaterialUboDirty, createPbrMaterial, createSolidTexture2D, createStandardMaterial, setAnimationAdditive, playAnimation, pauseAnimation, goToFrame, stopAnimation, createSceneContext, updateAnimationManager, setFog, setClipPlane, loadDdsEnvironment, loadEnvironment, createDefaultCamera, addToScene, createHemisphericLight, createAnimationManager, enableAnimationBlending, addAnimationGroup, disposeScene, createDirectionalLight, createPointLight, createSpotLight, createCsgFromMesh, csgSubtract, csgIntersect, csgUnion, createMeshFromCsg, createCsg2FromMesh, csg2Subtract, csg2Intersect, csg2Add, createMeshesFromCsg2, disposeCsg2, initializeCsg2Async, createMorphTargets, setMorphTargetWeights, createTransformNode, bakeCurrentTransformIntoVertices, loadSOG, loadSPZ, loadSplat, createTexture2DFromPixels, updateTexture2DFromPixels, loadBasisTexture2D, loadKtxTexture2D, loadTexture2D, getContainerMeshes, loadBabylon, loadGltf, resetVariant, getVariantNames, selectVariant, disposePicker, createGpuPicker, pickAsync, createAxisDragGizmo, attachAxisDragGizmoToNode, disposeAxisDragGizmo, createAxisScaleGizmo, attachAxisScaleGizmoToNode, disposeAxisScaleGizmo, createBoundingBoxGizmo, attachBoundingBoxGizmoToNode, disposeBoundingBoxGizmo, createCameraGizmo, attachCameraGizmoToCamera, disposeCameraGizmo, createLightGizmo, attachLightGizmoToLight, disposeLightGizmo, createPlaneDragGizmo, attachPlaneDragGizmoToNode, disposePlaneDragGizmo, createPlaneRotationGizmo, attachPlaneRotationGizmoToNode, disposePlaneRotationGizmo, createPositionGizmo, setPositionGizmoLocalCoordinates, attachPositionGizmoToNode, disposePositionGizmo, createRotationGizmo, setRotationGizmoLocalCoordinates, attachRotationGizmoToNode, disposeRotationGizmo, createScaleGizmo, setScaleGizmoLocalCoordinates, attachScaleGizmoToNode, disposeScaleGizmo, createUtilityLayer, registerUtilityLayer, disposeUtilityLayer, addBillboardSpriteIndex, updateBillboardSpriteIndex, loadSpriteAtlas, createFacingBillboardSystem, addFacingBillboardSystem, billboardBlendAdditive, billboardBlendAlpha, spriteBlendPremultiplied, spriteBlendAdditive, spriteBlendAlpha, createSprite2DLayer, addSprite2DIndex, createSpriteRenderer, registerSpriteRenderer, updateSprite2DIndex, createPcfSpotlightShadowGenerator, createPcfDirectionalShadowGenerator, createEsmDirectionalShadowGenerator, setShadowTaskCasterMeshes, parseNodeMaterialFromSnippet, createGridMaterial, getByteFrequencyData, getFloatFrequencyData, getByteTimeDomainData, getFloatTimeDomainData, enableAnalyzer, setSpatialPosition, setSpatialOrientation, enableSpatial, setSpatialListenerPosition, setSpatialListener, updateSpatialAudio, enableStereo, setStereoPan, disposeAudioBus, setBusVolume, getMasterVolume, setMasterVolume, unlockAudioEngineAsync, createSoundAsync, createSoundBufferAsync, createStreamingSoundAsync, createAudioBusAsync, createSoundSourceAsync, createMicrophoneSoundSourceAsync, disposeAudioEngine, createAudioEngineAsync, disposeSoundSource, setSoundSourceVolume, playSound, pauseSound, resumeSound, stopSound, disposeSound, setSoundVolume, playStreamingSound, pauseStreamingSound, resumeStreamingSound, stopStreamingSound, preloadStreamingInstanceAsync, preloadStreamingInstancesAsync, disposeStreamingSound, setStreamingSoundVolume } from "@babylonjs/lite";
7
7
  class Color3 {
8
8
  constructor(r = 0, g2 = 0, b2 = 0) {
9
9
  this.r = r;
@@ -2132,7 +2132,7 @@ class AnimationGroup {
2132
2132
  get animatables() {
2133
2133
  if (this._lite) {
2134
2134
  const frameRate = this._lite.frameRate ?? 60;
2135
- return [{ masterFrame: this._lite.currentFrame * frameRate }];
2135
+ return [{ masterFrame: this._lite.currentTime * frameRate }];
2136
2136
  }
2137
2137
  return [];
2138
2138
  }
@@ -2157,7 +2157,7 @@ class AnimationGroup {
2157
2157
  if (this._lite) {
2158
2158
  const frameRate = this._lite.frameRate ?? 60;
2159
2159
  if (from !== void 0) {
2160
- this._lite.currentFrame = from / frameRate;
2160
+ this._lite.currentTime = from / frameRate;
2161
2161
  }
2162
2162
  this._lite.speedRatio = speedRatio;
2163
2163
  this._lite.loopAnimation = loop;
@@ -5694,6 +5694,1143 @@ function setByPath(target, path, value) {
5694
5694
  }
5695
5695
  current[parts[parts.length - 1]] = value;
5696
5696
  }
5697
+ const SoundState = {
5698
+ Stopping: 0,
5699
+ Stopped: 1,
5700
+ Starting: 2,
5701
+ Started: 3,
5702
+ FailedToStart: 4,
5703
+ Paused: 5
5704
+ };
5705
+ const AudioParameterRampShape = {
5706
+ Linear: "linear",
5707
+ Exponential: "exponential",
5708
+ Logarithmic: "logarithmic",
5709
+ None: "none"
5710
+ };
5711
+ const SpatialAudioAttachmentType = {
5712
+ Position: 1,
5713
+ Rotation: 2,
5714
+ PositionAndRotation: 3
5715
+ };
5716
+ function toLiteRamp(options) {
5717
+ if (!options) {
5718
+ return void 0;
5719
+ }
5720
+ return { duration: options.duration, shape: options.shape };
5721
+ }
5722
+ function readNodePosition(node) {
5723
+ var _a;
5724
+ if (!node) {
5725
+ return null;
5726
+ }
5727
+ return ((_a = node.getAbsolutePosition) == null ? void 0 : _a.call(node)) ?? node.absolutePosition ?? node.position ?? null;
5728
+ }
5729
+ function readNodeRotation(node) {
5730
+ return (node == null ? void 0 : node.rotationQuaternion) ?? null;
5731
+ }
5732
+ class AbstractAudioNode {
5733
+ constructor(engine) {
5734
+ /** The engine that owns this node. */
5735
+ __publicField(this, "engine");
5736
+ /** Fires when this node is disposed. */
5737
+ __publicField(this, "onDisposeObservable", new Observable());
5738
+ this.engine = engine;
5739
+ }
5740
+ /** Disposes the node. */
5741
+ dispose() {
5742
+ this.onDisposeObservable.notifyObservers(this);
5743
+ this.onDisposeObservable.clear();
5744
+ }
5745
+ }
5746
+ class AbstractNamedAudioNode extends AbstractAudioNode {
5747
+ constructor(name, engine) {
5748
+ super(engine);
5749
+ /** Fires when {@link name} changes. */
5750
+ __publicField(this, "onNameChangedObservable", new Observable());
5751
+ __publicField(this, "_name");
5752
+ this._name = name;
5753
+ engine._addNode(this);
5754
+ }
5755
+ /** The node name. */
5756
+ get name() {
5757
+ return this._name;
5758
+ }
5759
+ set name(value) {
5760
+ const oldName = this._name;
5761
+ if (oldName === value) {
5762
+ return;
5763
+ }
5764
+ this._name = value;
5765
+ this.onNameChangedObservable.notifyObservers({ newName: value, oldName, node: this });
5766
+ }
5767
+ dispose() {
5768
+ this.engine._removeNode(this);
5769
+ this.onNameChangedObservable.clear();
5770
+ super.dispose();
5771
+ }
5772
+ }
5773
+ class AbstractAudioOutNode extends AbstractNamedAudioNode {
5774
+ constructor() {
5775
+ super(...arguments);
5776
+ __publicField(this, "_volume", 1);
5777
+ __publicField(this, "_analyzer", null);
5778
+ }
5779
+ /** The node output volume. */
5780
+ get volume() {
5781
+ return this._volume;
5782
+ }
5783
+ set volume(value) {
5784
+ this.setVolume(value);
5785
+ }
5786
+ /** Lazily-built audio analyzer for this node's output. */
5787
+ get analyzer() {
5788
+ return this._analyzer ?? (this._analyzer = new AbstractAudioAnalyzer(this._spatialHost()));
5789
+ }
5790
+ /** Sets the volume, optionally ramping. */
5791
+ setVolume(value, options) {
5792
+ this._volume = value;
5793
+ this._applyVolume(value, options);
5794
+ }
5795
+ dispose() {
5796
+ var _a;
5797
+ (_a = this._analyzer) == null ? void 0 : _a.dispose();
5798
+ this._analyzer = null;
5799
+ super.dispose();
5800
+ }
5801
+ }
5802
+ class AbstractStereoAudio {
5803
+ /** @internal */
5804
+ constructor(host) {
5805
+ __publicField(this, "_host");
5806
+ __publicField(this, "_pan", 0);
5807
+ __publicField(this, "_enabled", false);
5808
+ this._host = host;
5809
+ }
5810
+ /** Stereo pan, `-1` (left) to `1` (right). */
5811
+ get pan() {
5812
+ return this._pan;
5813
+ }
5814
+ set pan(value) {
5815
+ this._pan = value;
5816
+ if (!this._enabled) {
5817
+ enableStereo(this._host, { pan: value });
5818
+ this._enabled = true;
5819
+ } else {
5820
+ setStereoPan(this._host, value);
5821
+ }
5822
+ }
5823
+ }
5824
+ class AbstractAudioAnalyzer {
5825
+ /** @internal */
5826
+ constructor(host) {
5827
+ __publicField(this, "_host");
5828
+ __publicField(this, "_fftSize", 2048);
5829
+ __publicField(this, "_minDecibels", -100);
5830
+ __publicField(this, "_maxDecibels", -30);
5831
+ __publicField(this, "_smoothing", 0.8);
5832
+ __publicField(this, "_enabled", false);
5833
+ this._host = host;
5834
+ }
5835
+ /** FFT window size. */
5836
+ get fftSize() {
5837
+ return this._fftSize;
5838
+ }
5839
+ set fftSize(value) {
5840
+ this._fftSize = value;
5841
+ this._reapply();
5842
+ }
5843
+ /** Number of frequency bins (`fftSize / 2`). */
5844
+ get frequencyBinCount() {
5845
+ return this._fftSize / 2;
5846
+ }
5847
+ /** Whether the analyzer is enabled. */
5848
+ get isEnabled() {
5849
+ return this._enabled;
5850
+ }
5851
+ /** Minimum dB. */
5852
+ get minDecibels() {
5853
+ return this._minDecibels;
5854
+ }
5855
+ set minDecibels(value) {
5856
+ this._minDecibels = value;
5857
+ this._reapply();
5858
+ }
5859
+ /** Maximum dB. */
5860
+ get maxDecibels() {
5861
+ return this._maxDecibels;
5862
+ }
5863
+ set maxDecibels(value) {
5864
+ this._maxDecibels = value;
5865
+ this._reapply();
5866
+ }
5867
+ /** Time-averaging constant `[0, 1]`. */
5868
+ get smoothing() {
5869
+ return this._smoothing;
5870
+ }
5871
+ set smoothing(value) {
5872
+ this._smoothing = value;
5873
+ this._reapply();
5874
+ }
5875
+ /** Builds (enables) the analyzer tap. */
5876
+ async enableAsync() {
5877
+ this._apply();
5878
+ }
5879
+ /** Returns the byte frequency-domain data. Empty when disabled. */
5880
+ getByteFrequencyData() {
5881
+ if (!this._enabled) {
5882
+ return new Uint8Array(0);
5883
+ }
5884
+ const out = new Uint8Array(this.frequencyBinCount);
5885
+ getByteFrequencyData(this._host, out);
5886
+ return out;
5887
+ }
5888
+ /** Returns the float frequency-domain data. Empty when disabled. */
5889
+ getFloatFrequencyData() {
5890
+ if (!this._enabled) {
5891
+ return new Float32Array(0);
5892
+ }
5893
+ const out = new Float32Array(this.frequencyBinCount);
5894
+ getFloatFrequencyData(this._host, out);
5895
+ return out;
5896
+ }
5897
+ /** Returns the byte time-domain data. Empty when disabled. */
5898
+ getByteTimeDomainData() {
5899
+ if (!this._enabled) {
5900
+ return new Uint8Array(0);
5901
+ }
5902
+ const out = new Uint8Array(this._fftSize);
5903
+ getByteTimeDomainData(this._host, out);
5904
+ return out;
5905
+ }
5906
+ /** Returns the float time-domain data. Empty when disabled. */
5907
+ getFloatTimeDomainData() {
5908
+ if (!this._enabled) {
5909
+ return new Float32Array(0);
5910
+ }
5911
+ const out = new Float32Array(this._fftSize);
5912
+ getFloatTimeDomainData(this._host, out);
5913
+ return out;
5914
+ }
5915
+ /** Disposes the analyzer (Lite tears it down with the host). */
5916
+ dispose() {
5917
+ this._enabled = false;
5918
+ }
5919
+ _apply() {
5920
+ enableAnalyzer(this._host, {
5921
+ fftSize: this._fftSize,
5922
+ minDecibels: this._minDecibels,
5923
+ maxDecibels: this._maxDecibels,
5924
+ smoothing: this._smoothing
5925
+ });
5926
+ this._enabled = true;
5927
+ }
5928
+ _reapply() {
5929
+ if (this._enabled) {
5930
+ this._apply();
5931
+ }
5932
+ }
5933
+ }
5934
+ class AbstractSpatialAudio {
5935
+ /** @internal */
5936
+ constructor(host) {
5937
+ __publicField(this, "_host");
5938
+ __publicField(this, "_enabled", false);
5939
+ __publicField(this, "_position", new Vector3(0, 0, 0));
5940
+ __publicField(this, "_orientation", new Vector3(1, 0, 0));
5941
+ __publicField(this, "_rotationQuaternion", new Quaternion(0, 0, 0, 1));
5942
+ /** Cone inner angle, radians. */
5943
+ __publicField(this, "coneInnerAngle", 2 * Math.PI);
5944
+ /** Cone outer angle, radians. */
5945
+ __publicField(this, "coneOuterAngle", 2 * Math.PI);
5946
+ /** Volume outside the cone. */
5947
+ __publicField(this, "coneOuterVolume", 0);
5948
+ /** Distance attenuation model. */
5949
+ __publicField(this, "distanceModel", "linear");
5950
+ /** Max distance. */
5951
+ __publicField(this, "maxDistance", 1e4);
5952
+ /** Reference / min distance. */
5953
+ __publicField(this, "minDistance", 1);
5954
+ /** Minimum time between auto-updates, seconds. */
5955
+ __publicField(this, "minUpdateTime", 0);
5956
+ /** Enable left/right panning. */
5957
+ __publicField(this, "panningEnabled", true);
5958
+ /** Panning algorithm. */
5959
+ __publicField(this, "panningModel", "equalpower");
5960
+ /** Roll-off factor. */
5961
+ __publicField(this, "rolloffFactor", 1);
5962
+ /** Whether following a scene node. */
5963
+ __publicField(this, "useBoundingBox", false);
5964
+ /** Which transform components are followed. */
5965
+ __publicField(this, "attachmentType", SpatialAudioAttachmentType.PositionAndRotation);
5966
+ __publicField(this, "_attachedNode", null);
5967
+ this._host = host;
5968
+ }
5969
+ /** Source world position. */
5970
+ get position() {
5971
+ return this._position;
5972
+ }
5973
+ set position(value) {
5974
+ this._position = value;
5975
+ this._ensure();
5976
+ setSpatialPosition(this._host, value);
5977
+ }
5978
+ /** Source facing direction. */
5979
+ get orientation() {
5980
+ return this._orientation;
5981
+ }
5982
+ set orientation(value) {
5983
+ this._orientation = value;
5984
+ this._ensure();
5985
+ setSpatialOrientation(this._host, value);
5986
+ }
5987
+ /** Source rotation quaternion. */
5988
+ get rotationQuaternion() {
5989
+ return this._rotationQuaternion;
5990
+ }
5991
+ set rotationQuaternion(value) {
5992
+ this._rotationQuaternion = value;
5993
+ this._reapply();
5994
+ }
5995
+ /** Whether attached to a scene node. */
5996
+ get isAttached() {
5997
+ return this._attachedNode !== null;
5998
+ }
5999
+ /** The scene node this source follows, if any. */
6000
+ get attachedNode() {
6001
+ return this._attachedNode;
6002
+ }
6003
+ /** Follows a scene node's world transform. */
6004
+ attach(sceneNode, useBoundingBox = false, attachmentType = SpatialAudioAttachmentType.PositionAndRotation) {
6005
+ this._attachedNode = sceneNode;
6006
+ this.useBoundingBox = useBoundingBox;
6007
+ this.attachmentType = attachmentType;
6008
+ this._ensure();
6009
+ this.update();
6010
+ }
6011
+ /** Stops following a scene node. */
6012
+ detach() {
6013
+ this._attachedNode = null;
6014
+ }
6015
+ /** Pulls the attached node's current world position/rotation into the source. */
6016
+ update() {
6017
+ const node = this._attachedNode;
6018
+ if (!node) {
6019
+ return;
6020
+ }
6021
+ let dirty = false;
6022
+ if ((this.attachmentType & SpatialAudioAttachmentType.Position) !== 0) {
6023
+ const pos = readNodePosition(node);
6024
+ if (pos) {
6025
+ this._position = new Vector3(pos.x, pos.y, pos.z);
6026
+ dirty = true;
6027
+ }
6028
+ }
6029
+ if ((this.attachmentType & SpatialAudioAttachmentType.Rotation) !== 0) {
6030
+ const quat = readNodeRotation(node);
6031
+ if (quat) {
6032
+ this._rotationQuaternion = new Quaternion(quat.x, quat.y, quat.z, quat.w);
6033
+ dirty = true;
6034
+ }
6035
+ }
6036
+ if (dirty) {
6037
+ enableSpatial(this._host, this._options());
6038
+ this._enabled = true;
6039
+ }
6040
+ }
6041
+ /** Disposes the spatial sub-node (Lite tears it down with the host). */
6042
+ dispose() {
6043
+ this._attachedNode = null;
6044
+ this._enabled = false;
6045
+ }
6046
+ _ensure() {
6047
+ if (!this._enabled) {
6048
+ enableSpatial(this._host, this._options());
6049
+ this._enabled = true;
6050
+ }
6051
+ }
6052
+ _reapply() {
6053
+ if (this._enabled) {
6054
+ enableSpatial(this._host, this._options());
6055
+ }
6056
+ }
6057
+ _options() {
6058
+ return {
6059
+ position: this._position,
6060
+ orientation: this._orientation,
6061
+ rotationQuaternion: this._rotationQuaternion,
6062
+ panningEnabled: this.panningEnabled,
6063
+ panningModel: this.panningModel,
6064
+ distanceModel: this.distanceModel,
6065
+ minDistance: this.minDistance,
6066
+ maxDistance: this.maxDistance,
6067
+ rolloffFactor: this.rolloffFactor,
6068
+ coneInnerAngle: this.coneInnerAngle,
6069
+ coneOuterAngle: this.coneOuterAngle,
6070
+ coneOuterVolume: this.coneOuterVolume
6071
+ };
6072
+ }
6073
+ }
6074
+ class AbstractSpatialAudioListener {
6075
+ /** @internal */
6076
+ constructor(engine) {
6077
+ __publicField(this, "_engine");
6078
+ __publicField(this, "_position", new Vector3(0, 0, 0));
6079
+ __publicField(this, "_rotation", new Vector3(0, 0, 0));
6080
+ __publicField(this, "_rotationQuaternion", new Quaternion(0, 0, 0, 1));
6081
+ __publicField(this, "_attachedNode", null);
6082
+ /** Minimum time between auto-updates, seconds. */
6083
+ __publicField(this, "minUpdateTime", 0);
6084
+ this._engine = engine;
6085
+ }
6086
+ /** Whether attached to a scene node. */
6087
+ get isAttached() {
6088
+ return this._attachedNode !== null;
6089
+ }
6090
+ /** The scene node the listener follows, if any. */
6091
+ get attachedNode() {
6092
+ return this._attachedNode;
6093
+ }
6094
+ /** Listener world position. */
6095
+ get position() {
6096
+ return this._position;
6097
+ }
6098
+ set position(value) {
6099
+ this._position = value;
6100
+ setSpatialListenerPosition(this._engine, value);
6101
+ }
6102
+ /** Listener Euler rotation. */
6103
+ get rotation() {
6104
+ return this._rotation;
6105
+ }
6106
+ set rotation(value) {
6107
+ this._rotation = value;
6108
+ }
6109
+ /** Listener rotation quaternion. */
6110
+ get rotationQuaternion() {
6111
+ return this._rotationQuaternion;
6112
+ }
6113
+ set rotationQuaternion(value) {
6114
+ this._rotationQuaternion = value;
6115
+ setSpatialListener(this._engine, { rotationQuaternion: value });
6116
+ }
6117
+ /** Follows a scene node's world transform. */
6118
+ attach(sceneNode) {
6119
+ this._attachedNode = sceneNode;
6120
+ this.update();
6121
+ }
6122
+ /** Stops following a scene node. */
6123
+ detach() {
6124
+ this._attachedNode = null;
6125
+ }
6126
+ /** Pulls the attached node's current world position/rotation into the listener. */
6127
+ update() {
6128
+ const node = this._attachedNode;
6129
+ const pos = readNodePosition(node);
6130
+ if (pos) {
6131
+ this._position = new Vector3(pos.x, pos.y, pos.z);
6132
+ setSpatialListenerPosition(this._engine, pos);
6133
+ }
6134
+ const quat = readNodeRotation(node);
6135
+ if (quat) {
6136
+ this._rotationQuaternion = new Quaternion(quat.x, quat.y, quat.z, quat.w);
6137
+ setSpatialListener(this._engine, { rotationQuaternion: this._rotationQuaternion });
6138
+ }
6139
+ updateSpatialAudio(this._engine);
6140
+ }
6141
+ }
6142
+ class AbstractAudioBus extends AbstractAudioOutNode {
6143
+ }
6144
+ class AudioBus extends AbstractAudioBus {
6145
+ /** @internal */
6146
+ constructor(engine, lite, outBus, volume = 1) {
6147
+ super(lite.name, engine);
6148
+ /** @internal The backing Lite bus. */
6149
+ __publicField(this, "_lite");
6150
+ __publicField(this, "_spatial", null);
6151
+ __publicField(this, "_stereo", null);
6152
+ __publicField(this, "_outBus");
6153
+ this._lite = lite;
6154
+ this._outBus = outBus;
6155
+ this._volume = volume;
6156
+ }
6157
+ /** The output bus this bus routes to. */
6158
+ get outBus() {
6159
+ return this._outBus;
6160
+ }
6161
+ set outBus(value) {
6162
+ if (this._outBus === value) {
6163
+ return;
6164
+ }
6165
+ rerouteLiteOutBus(this._lite, unwrapBus(value) ?? null);
6166
+ this._outBus = value;
6167
+ }
6168
+ /** Lazily-built spatial sub-property. */
6169
+ get spatial() {
6170
+ return this._spatial ?? (this._spatial = new AbstractSpatialAudio(this._lite));
6171
+ }
6172
+ /** Lazily-built stereo sub-property. */
6173
+ get stereo() {
6174
+ return this._stereo ?? (this._stereo = new AbstractStereoAudio(this._lite));
6175
+ }
6176
+ getClassName() {
6177
+ return "AudioBus";
6178
+ }
6179
+ dispose() {
6180
+ disposeAudioBus(this._lite);
6181
+ super.dispose();
6182
+ }
6183
+ _applyVolume(value, options) {
6184
+ setBusVolume(this._lite, value, toLiteRamp(options));
6185
+ }
6186
+ _spatialHost() {
6187
+ return this._lite;
6188
+ }
6189
+ }
6190
+ class MainAudioBus extends AbstractAudioBus {
6191
+ /** @internal */
6192
+ constructor(engine, lite) {
6193
+ super(lite.name, engine);
6194
+ /** @internal The backing Lite main bus. */
6195
+ __publicField(this, "_lite");
6196
+ this._lite = lite;
6197
+ }
6198
+ getClassName() {
6199
+ return "MainAudioBus";
6200
+ }
6201
+ _applyVolume(value, options) {
6202
+ setBusVolume(this._lite, value, toLiteRamp(options));
6203
+ }
6204
+ _spatialHost() {
6205
+ return unsupported("MainAudioBus.analyzer", "Main buses have no analyzer; attach one to a sound or generic AudioBus instead.");
6206
+ }
6207
+ }
6208
+ class AbstractSoundSource extends AbstractAudioOutNode {
6209
+ constructor(name, engine, outBus) {
6210
+ super(name, engine);
6211
+ __publicField(this, "_spatial", null);
6212
+ __publicField(this, "_stereo", null);
6213
+ __publicField(this, "_outBus");
6214
+ this._outBus = outBus;
6215
+ }
6216
+ /** The output bus this source routes to. */
6217
+ get outBus() {
6218
+ return this._outBus;
6219
+ }
6220
+ set outBus(value) {
6221
+ if (this._outBus === value) {
6222
+ return;
6223
+ }
6224
+ rerouteLiteOutBus(this._spatialHost(), unwrapBus(value) ?? null);
6225
+ this._outBus = value;
6226
+ }
6227
+ /** Lazily-built spatial sub-property. */
6228
+ get spatial() {
6229
+ return this._spatial ?? (this._spatial = new AbstractSpatialAudio(this._spatialHost()));
6230
+ }
6231
+ /** Lazily-built stereo sub-property. */
6232
+ get stereo() {
6233
+ return this._stereo ?? (this._stereo = new AbstractStereoAudio(this._spatialHost()));
6234
+ }
6235
+ }
6236
+ class SoundSource extends AbstractSoundSource {
6237
+ /** @internal */
6238
+ constructor(engine, lite, outBus, volume = 1) {
6239
+ super(lite.name, engine, outBus);
6240
+ /** @internal The backing Lite input source. */
6241
+ __publicField(this, "_lite");
6242
+ this._lite = lite;
6243
+ this._volume = volume;
6244
+ }
6245
+ getClassName() {
6246
+ return "SoundSource";
6247
+ }
6248
+ dispose() {
6249
+ disposeSoundSource(this._lite);
6250
+ super.dispose();
6251
+ }
6252
+ _applyVolume(value, options) {
6253
+ setSoundSourceVolume(this._lite, value, toLiteRamp(options));
6254
+ }
6255
+ _spatialHost() {
6256
+ return this._lite;
6257
+ }
6258
+ }
6259
+ class AbstractSound extends AbstractSoundSource {
6260
+ constructor(name, engine, outBus) {
6261
+ super(name, engine, outBus);
6262
+ /** Fires when the sound finishes (all instances ended). */
6263
+ __publicField(this, "onEndedObservable", new Observable());
6264
+ engine._addSound(this);
6265
+ }
6266
+ dispose() {
6267
+ this.engine._removeSound(this);
6268
+ this.onEndedObservable.clear();
6269
+ super.dispose();
6270
+ }
6271
+ }
6272
+ class StaticSoundBuffer {
6273
+ /** @internal */
6274
+ constructor(engine, lite, name = "StaticSoundBuffer") {
6275
+ /** The engine that owns this buffer. */
6276
+ __publicField(this, "engine");
6277
+ /** The buffer name. */
6278
+ __publicField(this, "name");
6279
+ /** @internal The backing Lite sound buffer. */
6280
+ __publicField(this, "_lite");
6281
+ this.engine = engine;
6282
+ this._lite = lite;
6283
+ this.name = name;
6284
+ }
6285
+ /** Sample rate, Hz. */
6286
+ get sampleRate() {
6287
+ return this._lite.sampleRate;
6288
+ }
6289
+ /** Length in sample frames. */
6290
+ get length() {
6291
+ return this._lite.length;
6292
+ }
6293
+ /** Duration, seconds. */
6294
+ get duration() {
6295
+ return this._lite.duration;
6296
+ }
6297
+ /** Number of channels. */
6298
+ get channelCount() {
6299
+ return this._lite.channelCount;
6300
+ }
6301
+ /** Clones the buffer. Lite buffers are immutable, so the clone shares the data. */
6302
+ clone(options) {
6303
+ return new StaticSoundBuffer(this.engine, this._lite, (options == null ? void 0 : options.name) ?? this.name);
6304
+ }
6305
+ }
6306
+ class StaticSound extends AbstractSound {
6307
+ /** @internal */
6308
+ constructor(engine, lite, buffer, outBus, autoplay, name, volume = 1) {
6309
+ super(name ?? lite.name ?? "Sound", engine, outBus);
6310
+ /** @internal The backing Lite static sound. */
6311
+ __publicField(this, "_lite");
6312
+ __publicField(this, "_autoplay");
6313
+ __publicField(this, "_buffer");
6314
+ this._lite = lite;
6315
+ this._buffer = buffer;
6316
+ this._autoplay = autoplay;
6317
+ this._volume = volume;
6318
+ lite.onEnded.add(() => this.onEndedObservable.notifyObservers(this));
6319
+ }
6320
+ /** The decoded buffer this sound plays. */
6321
+ get buffer() {
6322
+ return this._buffer;
6323
+ }
6324
+ get activeInstancesCount() {
6325
+ return this._lite.instanceCount;
6326
+ }
6327
+ get autoplay() {
6328
+ return this._autoplay;
6329
+ }
6330
+ get state() {
6331
+ return this._lite.state;
6332
+ }
6333
+ get loop() {
6334
+ return this._lite._options.loop;
6335
+ }
6336
+ set loop(value) {
6337
+ this._lite._options.loop = value;
6338
+ }
6339
+ get startOffset() {
6340
+ return this._lite._options.startOffset;
6341
+ }
6342
+ set startOffset(value) {
6343
+ this._lite._options.startOffset = value;
6344
+ }
6345
+ get maxInstances() {
6346
+ return this._lite._options.maxInstances;
6347
+ }
6348
+ set maxInstances(value) {
6349
+ this._lite._options.maxInstances = value;
6350
+ }
6351
+ get duration() {
6352
+ return this._lite._options.duration;
6353
+ }
6354
+ set duration(value) {
6355
+ this._lite._options.duration = value;
6356
+ }
6357
+ get loopStart() {
6358
+ return this._lite._options.loopStart;
6359
+ }
6360
+ set loopStart(value) {
6361
+ this._lite._options.loopStart = value;
6362
+ }
6363
+ get loopEnd() {
6364
+ return this._lite._options.loopEnd;
6365
+ }
6366
+ set loopEnd(value) {
6367
+ this._lite._options.loopEnd = value;
6368
+ }
6369
+ get pitch() {
6370
+ return this._lite._options.pitch;
6371
+ }
6372
+ set pitch(value) {
6373
+ this._lite._options.pitch = value;
6374
+ for (const instance of this._lite._instances) {
6375
+ if (instance._sourceNode) {
6376
+ instance._sourceNode.detune.value = value;
6377
+ }
6378
+ }
6379
+ }
6380
+ get playbackRate() {
6381
+ return this._lite._options.playbackRate;
6382
+ }
6383
+ set playbackRate(value) {
6384
+ this._lite._options.playbackRate = value;
6385
+ for (const instance of this._lite._instances) {
6386
+ if (instance._sourceNode) {
6387
+ instance._sourceNode.playbackRate.value = value;
6388
+ }
6389
+ }
6390
+ }
6391
+ get currentTime() {
6392
+ return this.startOffset;
6393
+ }
6394
+ set currentTime(value) {
6395
+ this.startOffset = value;
6396
+ }
6397
+ play(options) {
6398
+ playSound(this._lite, options);
6399
+ }
6400
+ pause() {
6401
+ pauseSound(this._lite);
6402
+ }
6403
+ resume(options) {
6404
+ resumeSound(this._lite, options);
6405
+ }
6406
+ stop(options) {
6407
+ stopSound(this._lite, options);
6408
+ }
6409
+ /** Clones the sound (shares the decoded buffer). */
6410
+ async cloneAsync(options) {
6411
+ const outBus = (options == null ? void 0 : options.outBus) ?? this._outBus ?? void 0;
6412
+ return this.engine.createSoundAsync(this.name, this._buffer, { outBus });
6413
+ }
6414
+ getClassName() {
6415
+ return "StaticSound";
6416
+ }
6417
+ dispose() {
6418
+ disposeSound(this._lite);
6419
+ super.dispose();
6420
+ }
6421
+ _applyVolume(value, options) {
6422
+ setSoundVolume(this._lite, value, toLiteRamp(options));
6423
+ }
6424
+ _spatialHost() {
6425
+ return this._lite;
6426
+ }
6427
+ }
6428
+ class StreamingSound extends AbstractSound {
6429
+ /** @internal */
6430
+ constructor(engine, lite, outBus, options, name) {
6431
+ super(name ?? lite.name ?? "Sound", engine, outBus);
6432
+ /** @internal The backing Lite streaming sound. */
6433
+ __publicField(this, "_lite");
6434
+ __publicField(this, "_autoplay");
6435
+ __publicField(this, "_loop");
6436
+ __publicField(this, "_startOffset");
6437
+ __publicField(this, "_maxInstances");
6438
+ this._lite = lite;
6439
+ this._autoplay = options.autoplay ?? false;
6440
+ this._loop = options.loop ?? false;
6441
+ this._startOffset = options.startOffset ?? 0;
6442
+ this._maxInstances = options.maxInstances ?? Infinity;
6443
+ this._volume = options.volume ?? 1;
6444
+ lite.onEnded.add(() => this.onEndedObservable.notifyObservers(this));
6445
+ }
6446
+ /** Number of instances configured to preload. */
6447
+ get preloadCount() {
6448
+ return this._lite._options.preloadCount;
6449
+ }
6450
+ /** Number of instances that have finished preloading. */
6451
+ get preloadCompletedCount() {
6452
+ return this._lite.preloadCompletedCount;
6453
+ }
6454
+ get activeInstancesCount() {
6455
+ return this._lite.instanceCount;
6456
+ }
6457
+ get autoplay() {
6458
+ return this._autoplay;
6459
+ }
6460
+ get state() {
6461
+ return this._lite.state;
6462
+ }
6463
+ get loop() {
6464
+ return this._loop;
6465
+ }
6466
+ set loop(value) {
6467
+ this._loop = value;
6468
+ this._lite._options.loop = value;
6469
+ }
6470
+ get startOffset() {
6471
+ return this._startOffset;
6472
+ }
6473
+ set startOffset(value) {
6474
+ this._startOffset = value;
6475
+ this._lite._options.startOffset = value;
6476
+ }
6477
+ get maxInstances() {
6478
+ return this._maxInstances;
6479
+ }
6480
+ set maxInstances(value) {
6481
+ this._maxInstances = value;
6482
+ this._lite._options.maxInstances = value;
6483
+ }
6484
+ get currentTime() {
6485
+ return this._startOffset;
6486
+ }
6487
+ set currentTime(value) {
6488
+ this.startOffset = value;
6489
+ }
6490
+ play(options) {
6491
+ playStreamingSound(this._lite, options);
6492
+ }
6493
+ pause() {
6494
+ pauseStreamingSound(this._lite);
6495
+ }
6496
+ resume(options) {
6497
+ resumeStreamingSound(this._lite, options);
6498
+ }
6499
+ stop() {
6500
+ stopStreamingSound(this._lite);
6501
+ }
6502
+ /** Preloads a single instance. */
6503
+ preloadInstanceAsync() {
6504
+ return preloadStreamingInstanceAsync(this._lite);
6505
+ }
6506
+ /** Preloads `count` instances. */
6507
+ preloadInstancesAsync(count) {
6508
+ return preloadStreamingInstancesAsync(this._lite, count);
6509
+ }
6510
+ getClassName() {
6511
+ return "StreamingSound";
6512
+ }
6513
+ dispose() {
6514
+ disposeStreamingSound(this._lite);
6515
+ super.dispose();
6516
+ }
6517
+ _applyVolume(value, options) {
6518
+ setStreamingSoundVolume(this._lite, value, toLiteRamp(options));
6519
+ }
6520
+ _spatialHost() {
6521
+ return this._lite;
6522
+ }
6523
+ }
6524
+ const FormatMimeTypes = {
6525
+ aac: "audio/aac",
6526
+ ac3: "audio/ac3",
6527
+ flac: "audio/flac",
6528
+ m4a: "audio/mp4",
6529
+ mp3: 'audio/mpeg; codecs="mp3"',
6530
+ mp4: "audio/mp4",
6531
+ ogg: 'audio/ogg; codecs="vorbis"',
6532
+ wav: "audio/wav",
6533
+ webm: 'audio/webm; codecs="vorbis"'
6534
+ };
6535
+ function unwrapBus(bus) {
6536
+ if (!bus) {
6537
+ return void 0;
6538
+ }
6539
+ return bus._lite;
6540
+ }
6541
+ function liteBusInputNode(bus) {
6542
+ return "_graph" in bus ? bus._graph._in : bus._in;
6543
+ }
6544
+ function rerouteLiteOutBus(host, newOutBus) {
6545
+ const out = host._graph._out;
6546
+ const oldOutBus = host._outBus;
6547
+ if (oldOutBus) {
6548
+ try {
6549
+ out.disconnect(liteBusInputNode(oldOutBus));
6550
+ } catch {
6551
+ }
6552
+ }
6553
+ if (newOutBus) {
6554
+ out.connect(liteBusInputNode(newOutBus));
6555
+ }
6556
+ host._outBus = newOutBus;
6557
+ }
6558
+ function unwrapBufferSource(source) {
6559
+ if (source instanceof StaticSoundBuffer) {
6560
+ return source._lite;
6561
+ }
6562
+ return source;
6563
+ }
6564
+ const _AudioEngineV2 = class _AudioEngineV2 {
6565
+ /** @internal */
6566
+ constructor(lite) {
6567
+ /** Fires when a named node is added to the engine. */
6568
+ __publicField(this, "onNodeAddedObservable", new Observable());
6569
+ /** Fires when a named node is removed from the engine. */
6570
+ __publicField(this, "onNodeRemovedObservable", new Observable());
6571
+ /** Fires when the engine is disposed. */
6572
+ __publicField(this, "onDisposeObservable", new Observable());
6573
+ /** @internal The backing Lite audio engine. */
6574
+ __publicField(this, "_lite");
6575
+ __publicField(this, "_sounds", /* @__PURE__ */ new Set());
6576
+ __publicField(this, "_nodes", /* @__PURE__ */ new Set());
6577
+ __publicField(this, "_defaultMainBus", null);
6578
+ __publicField(this, "_listener", null);
6579
+ __publicField(this, "_mainOut", null);
6580
+ this._lite = lite;
6581
+ _AudioEngineV2._Instances.push(this);
6582
+ }
6583
+ /** All live audio engines. */
6584
+ static get Instances() {
6585
+ return _AudioEngineV2._Instances;
6586
+ }
6587
+ /** The audio context's current time, seconds. */
6588
+ get currentTime() {
6589
+ return this._lite.currentTime;
6590
+ }
6591
+ /** The context state. */
6592
+ get state() {
6593
+ return this._lite.state;
6594
+ }
6595
+ /** Master output volume. */
6596
+ get volume() {
6597
+ return getMasterVolume(this._lite);
6598
+ }
6599
+ set volume(value) {
6600
+ setMasterVolume(this._lite, value);
6601
+ }
6602
+ /** Default parameter ramp duration, seconds. */
6603
+ get parameterRampDuration() {
6604
+ return this._lite._rampDuration;
6605
+ }
6606
+ set parameterRampDuration(value) {
6607
+ this._lite._rampDuration = value;
6608
+ }
6609
+ /** The default main bus all sounds route to. */
6610
+ get defaultMainBus() {
6611
+ return this._defaultMainBus ?? (this._defaultMainBus = new MainAudioBus(this, this._lite._mainBus));
6612
+ }
6613
+ /** The spatial-audio listener (the "ears"). */
6614
+ get listener() {
6615
+ return this._listener ?? (this._listener = new AbstractSpatialAudioListener(this._lite));
6616
+ }
6617
+ /** The engine output node. */
6618
+ get mainOut() {
6619
+ return this._mainOut ?? (this._mainOut = new MainOutNode(this));
6620
+ }
6621
+ /** All live sounds. */
6622
+ get sounds() {
6623
+ return Array.from(this._sounds);
6624
+ }
6625
+ /** All live named nodes. */
6626
+ get nodes() {
6627
+ return this._nodes;
6628
+ }
6629
+ /** Sets the master volume, optionally ramping. */
6630
+ setVolume(value, options) {
6631
+ setMasterVolume(this._lite, value, toLiteRamp(options));
6632
+ }
6633
+ /** Whether the given audio format/extension can be decoded. */
6634
+ isFormatValid(format) {
6635
+ const mimeType = FormatMimeTypes[format.toLowerCase()];
6636
+ if (mimeType === void 0) {
6637
+ return false;
6638
+ }
6639
+ if (typeof Audio === "undefined") {
6640
+ return true;
6641
+ }
6642
+ return new Audio().canPlayType(mimeType) !== "";
6643
+ }
6644
+ /** Suspends the engine context. */
6645
+ async pauseAsync() {
6646
+ const ctx = this._lite._ctx;
6647
+ if (typeof ctx.suspend === "function" && ctx.state === "running") {
6648
+ await ctx.suspend();
6649
+ }
6650
+ }
6651
+ /** Resumes the engine context. */
6652
+ async resumeAsync() {
6653
+ await unlockAudioEngineAsync(this._lite);
6654
+ }
6655
+ /** Resumes the engine context (alias of {@link resumeAsync}). */
6656
+ async unlockAsync() {
6657
+ await unlockAudioEngineAsync(this._lite);
6658
+ }
6659
+ /** Creates a buffer-backed sound. */
6660
+ async createSoundAsync(name, source, options) {
6661
+ const liteOptions = toLiteStaticSoundOptions(name, options);
6662
+ const lite = await createSoundAsync(this._lite, unwrapBufferSource(source), liteOptions);
6663
+ const buffer = new StaticSoundBuffer(this, lite.buffer, name);
6664
+ return new StaticSound(this, lite, buffer, (options == null ? void 0 : options.outBus) ?? this.defaultMainBus, (options == null ? void 0 : options.autoplay) ?? false, name, (options == null ? void 0 : options.volume) ?? 1);
6665
+ }
6666
+ /** Creates a decoded sound buffer. */
6667
+ async createSoundBufferAsync(source, options) {
6668
+ const lite = await createSoundBufferAsync(this._lite, unwrapBufferSource(source), { skipCodecCheck: options == null ? void 0 : options.skipCodecCheck });
6669
+ return new StaticSoundBuffer(this, lite);
6670
+ }
6671
+ /** Creates a streaming, media-element-backed sound. */
6672
+ async createStreamingSoundAsync(name, source, options) {
6673
+ const liteOptions = {
6674
+ autoplay: options == null ? void 0 : options.autoplay,
6675
+ loop: options == null ? void 0 : options.loop,
6676
+ maxInstances: options == null ? void 0 : options.maxInstances,
6677
+ outBus: unwrapBus(options == null ? void 0 : options.outBus),
6678
+ preloadCount: options == null ? void 0 : options.preloadCount,
6679
+ startOffset: options == null ? void 0 : options.startOffset,
6680
+ volume: options == null ? void 0 : options.volume
6681
+ };
6682
+ const lite = await createStreamingSoundAsync(this._lite, source, liteOptions);
6683
+ return new StreamingSound(this, lite, (options == null ? void 0 : options.outBus) ?? this.defaultMainBus, options ?? {}, name);
6684
+ }
6685
+ /** Creates a generic mixer bus. */
6686
+ async createBusAsync(name, options) {
6687
+ const lite = await createAudioBusAsync(this._lite, name, {
6688
+ volume: options == null ? void 0 : options.volume,
6689
+ outBus: unwrapBus(options == null ? void 0 : options.outBus)
6690
+ });
6691
+ return new AudioBus(this, lite, (options == null ? void 0 : options.outBus) ?? this.defaultMainBus, (options == null ? void 0 : options.volume) ?? 1);
6692
+ }
6693
+ /**
6694
+ * Creates a main bus. Babylon Lite builds a single default main bus per engine
6695
+ * and does not expose creating additional ones, so this resolves the default
6696
+ * main bus.
6697
+ */
6698
+ async createMainBusAsync(_name, _options) {
6699
+ return this.defaultMainBus;
6700
+ }
6701
+ /** Wraps an arbitrary Web Audio node as a sound source. */
6702
+ async createSoundSourceAsync(name, source, options) {
6703
+ const lite = await createSoundSourceAsync(this._lite, source, {
6704
+ name,
6705
+ outBus: unwrapBus(options == null ? void 0 : options.outBus),
6706
+ outBusAutoDefault: options == null ? void 0 : options.outBusAutoDefault,
6707
+ volume: options == null ? void 0 : options.volume
6708
+ });
6709
+ return new SoundSource(this, lite, (options == null ? void 0 : options.outBus) ?? null, (options == null ? void 0 : options.volume) ?? 1);
6710
+ }
6711
+ /** Creates a microphone-backed sound source. */
6712
+ async createMicrophoneSoundSourceAsync(name, options) {
6713
+ const lite = await createMicrophoneSoundSourceAsync(this._lite, {
6714
+ name,
6715
+ outBus: unwrapBus(options == null ? void 0 : options.outBus),
6716
+ outBusAutoDefault: options == null ? void 0 : options.outBusAutoDefault,
6717
+ volume: options == null ? void 0 : options.volume
6718
+ });
6719
+ return new SoundSource(this, lite, (options == null ? void 0 : options.outBus) ?? null, (options == null ? void 0 : options.volume) ?? 1);
6720
+ }
6721
+ /** Disposes the engine and all its sounds/buses. */
6722
+ dispose() {
6723
+ disposeAudioEngine(this._lite);
6724
+ this.onDisposeObservable.notifyObservers(this);
6725
+ this.onDisposeObservable.clear();
6726
+ this.onNodeAddedObservable.clear();
6727
+ this.onNodeRemovedObservable.clear();
6728
+ this._sounds.clear();
6729
+ this._nodes.clear();
6730
+ const i2 = _AudioEngineV2._Instances.indexOf(this);
6731
+ if (i2 !== -1) {
6732
+ _AudioEngineV2._Instances.splice(i2, 1);
6733
+ }
6734
+ if (LastCreatedEngine === this) {
6735
+ LastCreatedEngine = null;
6736
+ }
6737
+ }
6738
+ /** @internal */
6739
+ _addSound(sound) {
6740
+ this._sounds.add(sound);
6741
+ }
6742
+ /** @internal */
6743
+ _removeSound(sound) {
6744
+ this._sounds.delete(sound);
6745
+ }
6746
+ /** @internal */
6747
+ _addNode(node) {
6748
+ this._nodes.add(node);
6749
+ this.onNodeAddedObservable.notifyObservers(node);
6750
+ }
6751
+ /** @internal */
6752
+ _removeNode(node) {
6753
+ if (this._nodes.delete(node)) {
6754
+ this.onNodeRemovedObservable.notifyObservers(node);
6755
+ }
6756
+ }
6757
+ };
6758
+ __publicField(_AudioEngineV2, "_Instances", []);
6759
+ let AudioEngineV2 = _AudioEngineV2;
6760
+ class MainOutNode extends AbstractAudioNode {
6761
+ constructor(engine) {
6762
+ super(engine);
6763
+ }
6764
+ getClassName() {
6765
+ return "_MainAudioOut";
6766
+ }
6767
+ }
6768
+ function toLiteStaticSoundOptions(_name, options) {
6769
+ return {
6770
+ autoplay: options == null ? void 0 : options.autoplay,
6771
+ duration: options == null ? void 0 : options.duration,
6772
+ loop: options == null ? void 0 : options.loop,
6773
+ loopEnd: options == null ? void 0 : options.loopEnd,
6774
+ loopStart: options == null ? void 0 : options.loopStart,
6775
+ maxInstances: options == null ? void 0 : options.maxInstances,
6776
+ outBus: unwrapBus(options == null ? void 0 : options.outBus),
6777
+ pitch: options == null ? void 0 : options.pitch,
6778
+ playbackRate: options == null ? void 0 : options.playbackRate,
6779
+ startOffset: options == null ? void 0 : options.startOffset,
6780
+ volume: options == null ? void 0 : options.volume,
6781
+ skipCodecCheck: options == null ? void 0 : options.skipCodecCheck
6782
+ };
6783
+ }
6784
+ function toLiteEngineOptions(options) {
6785
+ return {
6786
+ audioContext: options == null ? void 0 : options.audioContext,
6787
+ volume: options == null ? void 0 : options.volume,
6788
+ parameterRampDuration: options == null ? void 0 : options.parameterRampDuration,
6789
+ resumeOnInteraction: options == null ? void 0 : options.resumeOnInteraction,
6790
+ resumeOnPause: options == null ? void 0 : options.resumeOnPause,
6791
+ resumeOnPauseRetryInterval: options == null ? void 0 : options.resumeOnPauseRetryInterval
6792
+ };
6793
+ }
6794
+ let LastCreatedEngine = null;
6795
+ const OnAudioEngineV2CreatedObservable = new Observable();
6796
+ function LastCreatedAudioEngine() {
6797
+ return LastCreatedEngine;
6798
+ }
6799
+ function resolveEngine(engine) {
6800
+ const resolved = engine ?? LastCreatedEngine;
6801
+ if (!resolved) {
6802
+ return unsupported("AudioV2 factory", "No audio engine available. Call CreateAudioEngineAsync(...) first or pass an engine.");
6803
+ }
6804
+ return resolved;
6805
+ }
6806
+ async function CreateAudioEngineAsync(options) {
6807
+ const lite = await createAudioEngineAsync(toLiteEngineOptions(options));
6808
+ const engine = new AudioEngineV2(lite);
6809
+ LastCreatedEngine = engine;
6810
+ OnAudioEngineV2CreatedObservable.notifyObservers(engine);
6811
+ return engine;
6812
+ }
6813
+ function CreateSoundAsync(name, source, options, engine) {
6814
+ return resolveEngine(engine).createSoundAsync(name, source, options);
6815
+ }
6816
+ function CreateSoundBufferAsync(source, options, engine) {
6817
+ return resolveEngine(engine).createSoundBufferAsync(source, options);
6818
+ }
6819
+ function CreateStreamingSoundAsync(name, source, options, engine) {
6820
+ return resolveEngine(engine).createStreamingSoundAsync(name, source, options);
6821
+ }
6822
+ function CreateAudioBusAsync(name, options, engine) {
6823
+ return resolveEngine(engine).createBusAsync(name, options);
6824
+ }
6825
+ function CreateMainAudioBusAsync(name, options, engine) {
6826
+ return resolveEngine(engine).createMainBusAsync(name, options);
6827
+ }
6828
+ function CreateSoundSourceAsync(name, source, options, engine) {
6829
+ return resolveEngine(engine).createSoundSourceAsync(name, source, options);
6830
+ }
6831
+ function CreateMicrophoneSoundSourceAsync(name, options, engine) {
6832
+ return resolveEngine(engine).createMicrophoneSoundSourceAsync(name, options);
6833
+ }
5697
6834
  class MultiMaterial {
5698
6835
  constructor() {
5699
6836
  unsupported("MultiMaterial", "Babylon Lite uses one material per renderable. Split the mesh geometry by material into separate meshes instead.");
@@ -5962,9 +7099,19 @@ class SceneOptimizer {
5962
7099
  }
5963
7100
  export {
5964
7101
  AbstractAssetTask,
7102
+ AbstractAudioAnalyzer,
7103
+ AbstractAudioBus,
7104
+ AbstractAudioNode,
7105
+ AbstractAudioOutNode,
5965
7106
  AbstractEngine,
5966
7107
  A as AbstractMesh,
7108
+ AbstractNamedAudioNode,
5967
7109
  AbstractScene,
7110
+ AbstractSound,
7111
+ AbstractSoundSource,
7112
+ AbstractSpatialAudio,
7113
+ AbstractSpatialAudioListener,
7114
+ AbstractStereoAudio,
5968
7115
  Action,
5969
7116
  ActionManager,
5970
7117
  ActionManagerTriggers,
@@ -5981,7 +7128,10 @@ export {
5981
7128
  ArcRotateCamera,
5982
7129
  AssetContainer,
5983
7130
  AssetsManager,
7131
+ AudioBus,
5984
7132
  AudioEngine,
7133
+ AudioEngineV2,
7134
+ AudioParameterRampShape,
5985
7135
  AutoRotationBehavior,
5986
7136
  Axis,
5987
7137
  AxisDragGizmo,
@@ -6015,12 +7165,20 @@ export {
6015
7165
  ColorGradient,
6016
7166
  Condition,
6017
7167
  Constants,
7168
+ CreateAudioBusAsync,
7169
+ CreateAudioEngineAsync,
6018
7170
  C as CreateBox,
6019
7171
  b as CreateCylinder,
6020
7172
  c as CreateDisc,
6021
7173
  d as CreateGround,
7174
+ CreateMainAudioBusAsync,
7175
+ CreateMicrophoneSoundSourceAsync,
6022
7176
  e as CreatePlane,
7177
+ CreateSoundAsync,
7178
+ CreateSoundBufferAsync,
7179
+ CreateSoundSourceAsync,
6023
7180
  f as CreateSphere,
7181
+ CreateStreamingSoundAsync,
6024
7182
  g as CreateTorus,
6025
7183
  CubeTexture,
6026
7184
  CubicEase,
@@ -6072,6 +7230,7 @@ export {
6072
7230
  InitializeCSG2Async,
6073
7231
  I as InstancedMesh,
6074
7232
  KHR_materials_variants,
7233
+ LastCreatedAudioEngine,
6075
7234
  Layer,
6076
7235
  Light,
6077
7236
  LightGizmo,
@@ -6079,6 +7238,7 @@ export {
6079
7238
  LiteCompatError,
6080
7239
  LoadAssetContainerAsync,
6081
7240
  Logger,
7241
+ MainAudioBus,
6082
7242
  Material,
6083
7243
  Matrix,
6084
7244
  Mesh,
@@ -6093,6 +7253,7 @@ export {
6093
7253
  NullEngine,
6094
7254
  OBJFileLoader,
6095
7255
  Observable,
7256
+ OnAudioEngineV2CreatedObservable,
6096
7257
  OutlineRenderer,
6097
7258
  PBRAnisotropicConfiguration,
6098
7259
  PBRClearCoatConfiguration,
@@ -6121,7 +7282,7 @@ export {
6121
7282
  PushMaterial,
6122
7283
  QuadraticEase,
6123
7284
  QuarticEase,
6124
- Q as Quaternion,
7285
+ Quaternion,
6125
7286
  QuinticEase,
6126
7287
  RawTexture,
6127
7288
  Ray,
@@ -6149,7 +7310,10 @@ export {
6149
7310
  SmartArray,
6150
7311
  SolidParticleSystem,
6151
7312
  Sound,
7313
+ SoundSource,
7314
+ SoundState,
6152
7315
  Space,
7316
+ SpatialAudioAttachmentType,
6153
7317
  SpotLight,
6154
7318
  Sprite,
6155
7319
  SpriteManager,
@@ -6157,6 +7321,9 @@ export {
6157
7321
  SpritePackedManager,
6158
7322
  SpriteRenderer,
6159
7323
  StandardMaterial,
7324
+ StaticSound,
7325
+ StaticSoundBuffer,
7326
+ StreamingSound,
6160
7327
  StringDictionary,
6161
7328
  Tags,
6162
7329
  TargetCamera,