@woosh/meep-engine 2.61.0 → 2.63.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.
Files changed (56) hide show
  1. package/build/meep.cjs +1277 -1259
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +1277 -1259
  4. package/package.json +1 -1
  5. package/src/core/binary/EncodingBinaryBuffer.js +7 -43
  6. package/src/core/binary/EncodingBinaryBuffer.spec.js +16 -0
  7. package/src/core/bvh2/BinaryNode.js +16 -13
  8. package/src/core/bvh2/LeafNode.js +6 -3
  9. package/src/core/bvh2/bvh3/EBBVHLeafProxy.js +4 -2
  10. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js +81 -0
  11. package/src/core/cache/LoadingCache.js +4 -1
  12. package/src/core/collection/map/BiMap.js +49 -0
  13. package/src/core/geom/3d/aabb/AABB3.js +24 -36
  14. package/src/core/geom/3d/aabb/aabb3_array_compute_from_sphere.js +22 -0
  15. package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere.js +22 -0
  16. package/src/core/geom/3d/aabb/aabb3_array_intersects_sphere_array.js +11 -0
  17. package/src/core/geom/3d/aabb/aabb3_signed_distance_to_aabb3.js +28 -0
  18. package/src/core/geom/3d/aabb/serializeAABB3Quantized16Uint.js +19 -10
  19. package/src/core/geom/3d/tetrahedra/delaunay/Cavity.js +3 -4
  20. package/src/engine/ecs/components/Tag.d.ts +2 -0
  21. package/src/engine/ecs/components/Tag.js +19 -28
  22. package/src/engine/ecs/components/Tag.spec.js +47 -0
  23. package/src/engine/ecs/foliage/ecs/Foliage2System.js +3 -0
  24. package/src/engine/ecs/foliage/ecs/InstancedMeshComponent.js +4 -1
  25. package/src/engine/ecs/foliage/ecs/convertInstancedMeshComponents2Entities.js +64 -0
  26. package/src/engine/ecs/foliage/ecs/{InstancedMeshUtils.js → optimizeIndividualMeshesEntitiesToInstances.js} +11 -70
  27. package/src/engine/ecs/fow/FogOfWar.js +4 -0
  28. package/src/engine/ecs/fow/FogOfWarEditor.js +3 -0
  29. package/src/engine/ecs/terrain/TerrainPreview.js +45 -44
  30. package/src/engine/ecs/terrain/ecs/cling/ClingToTerrain.js +22 -4
  31. package/src/engine/ecs/terrain/tiles/TerrainTile.js +17 -12
  32. package/src/engine/graphics/camera/testClippingPlaneComputation.js +25 -27
  33. package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -4
  34. package/src/engine/graphics/ecs/mesh/Mesh.js +0 -11
  35. package/src/engine/graphics/ecs/mesh/MeshSystem.js +57 -67
  36. package/src/engine/graphics/ecs/path/testPathDisplaySystem.js +49 -52
  37. package/src/engine/graphics/ecs/path/tube/prototypeAnimatedPathMask.js +40 -42
  38. package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +43 -25
  39. package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +10 -6
  40. package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +37 -41
  41. package/src/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +44 -46
  42. package/src/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +24 -26
  43. package/src/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +40 -42
  44. package/src/engine/graphics/render/visibility/hiz/prototypeHiZ.js +36 -38
  45. package/src/engine/graphics/shadows/testShadowMapRendering.js +19 -19
  46. package/src/engine/grid/ORTHOGONAL_NEIGHBOURHOOD_MASK.js +11 -0
  47. package/src/engine/sound/dB2Volume.js +8 -0
  48. package/src/engine/sound/ecs/emitter/SoundEmitter.js +125 -99
  49. package/src/engine/sound/ecs/emitter/SoundEmitterComponentContext.js +4 -42
  50. package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +31 -121
  51. package/src/engine/sound/volume2dB.js +8 -0
  52. package/src/generation/theme/ThemeEngine.js +19 -53
  53. package/src/core/binary/stringToByteArray.js +0 -24
  54. package/src/engine/graphics/geometry/bvh/buffered/BVHFromBufferGeometry.js +0 -133
  55. package/src/engine/save/storage/LocalStorage.js +0 -148
  56. package/src/engine/save/storage/MsgPackCodec.js +0 -22
@@ -1,32 +1,31 @@
1
- import {mat4} from "gl-matrix";
1
+ import { mat4 } from "gl-matrix";
2
2
  import FacingDirectionSystem from "../../../../../../../model/game/ecs/system/FacingDirectionSystem.js";
3
- import {makeEngineOptionsModel} from "../../../../../../../model/game/options/makeEngineOptionsModel.js";
4
- import {enableEditor} from "../../../../../../editor/enableEditor.js";
5
- import {AABB3} from "../../../../../core/geom/3d/aabb/AABB3.js";
3
+ import { makeEngineOptionsModel } from "../../../../../../../model/game/options/makeEngineOptionsModel.js";
4
+ import { enableEditor } from "../../../../../../editor/enableEditor.js";
5
+ import { AABB3 } from "../../../../../core/geom/3d/aabb/AABB3.js";
6
6
  import Vector2 from "../../../../../core/geom/Vector2.js";
7
7
  import Vector3 from "../../../../../core/geom/Vector3.js";
8
- import {clamp} from "../../../../../core/math/clamp.js";
9
- import {inverseLerp} from "../../../../../core/math/inverseLerp.js";
10
- import {max2} from "../../../../../core/math/max2.js";
11
- import {min2} from "../../../../../core/math/min2.js";
12
- import {randomFloatBetween} from "../../../../../core/math/random/randomFloatBetween.js";
13
- import {seededRandom} from "../../../../../core/math/random/seededRandom.js";
14
- import {number_pretty_print} from "../../../../../core/primitives/numbers/number_pretty_print.js";
8
+ import { clamp } from "../../../../../core/math/clamp.js";
9
+ import { inverseLerp } from "../../../../../core/math/inverseLerp.js";
10
+ import { max2 } from "../../../../../core/math/max2.js";
11
+ import { min2 } from "../../../../../core/math/min2.js";
12
+ import { randomFloatBetween } from "../../../../../core/math/random/randomFloatBetween.js";
13
+ import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
14
+ import { number_pretty_print } from "../../../../../core/primitives/numbers/number_pretty_print.js";
15
15
  import LabelView from "../../../../../view/common/LabelView.js";
16
- import {MetricCollection} from "../../../../development/performance/MetricCollection.js";
17
- import {MetricStatistics} from "../../../../development/performance/MetricStatistics.js";
18
- import {AttachmentSystem} from "../../../../ecs/attachment/AttachmentSystem.js";
16
+ import { MetricCollection } from "../../../../development/performance/MetricCollection.js";
17
+ import { MetricStatistics } from "../../../../development/performance/MetricStatistics.js";
18
+ import { AttachmentSystem } from "../../../../ecs/attachment/AttachmentSystem.js";
19
19
  import Entity from "../../../../ecs/Entity.js";
20
- import {Foliage2System} from "../../../../ecs/foliage/ecs/Foliage2System.js";
21
- import {FogOfWarRevealerSystem} from "../../../../ecs/fow/FogOfWarRevealerSystem.js";
22
- import {FogOfWarSystem} from "../../../../ecs/fow/FogOfWarSystem.js";
20
+ import { FogOfWarRevealerSystem } from "../../../../ecs/fow/FogOfWarRevealerSystem.js";
21
+ import { FogOfWarSystem } from "../../../../ecs/fow/FogOfWarSystem.js";
23
22
  import GUIElement from "../../../../ecs/gui/GUIElement.js";
24
23
  import GUIElementSystem from "../../../../ecs/gui/GUIElementSystem.js";
25
24
  import HeadsUpDisplay from "../../../../ecs/gui/hud/HeadsUpDisplay.js";
26
25
  import HeadsUpDisplaySystem from "../../../../ecs/gui/hud/HeadsUpDisplaySystem.js";
27
26
  import ViewportPosition from "../../../../ecs/gui/position/ViewportPosition.js";
28
27
  import ViewportPositionSystem from "../../../../ecs/gui/position/ViewportPositionSystem.js";
29
- import {InverseKinematicsSystem} from "../../../../ecs/ik/InverseKinematicsSystem.js";
28
+ import { InverseKinematicsSystem } from "../../../../ecs/ik/InverseKinematicsSystem.js";
30
29
  import AnimationSystem from "../../../../ecs/systems/AnimationSystem.js";
31
30
  import MotionSystem from "../../../../ecs/systems/MotionSystem.js";
32
31
  import RenderSystem from "../../../../ecs/systems/RenderSystem.js";
@@ -36,37 +35,37 @@ import TagSystem from "../../../../ecs/systems/TagSystem.js";
36
35
  import TimerSystem from "../../../../ecs/systems/TimerSystem.js";
37
36
  import ClingToTerrainSystem from "../../../../ecs/terrain/ecs/cling/ClingToTerrainSystem.js";
38
37
  import TerrainSystem from "../../../../ecs/terrain/ecs/TerrainSystem.js";
39
- import {Transform} from "../../../../ecs/transform/Transform.js";
40
- import {EngineConfiguration} from "../../../../EngineConfiguration.js";
41
- import {EngineHarness} from "../../../../EngineHarness.js";
42
- import {GridPosition2TransformSystem} from "../../../../grid/grid2transform/GridPosition2TransformSystem.js";
38
+ import { Transform } from "../../../../ecs/transform/Transform.js";
39
+ import { EngineConfiguration } from "../../../../EngineConfiguration.js";
40
+ import { EngineHarness } from "../../../../EngineHarness.js";
41
+ import { GridPosition2TransformSystem } from "../../../../grid/grid2transform/GridPosition2TransformSystem.js";
43
42
  import GridPositionSystem from "../../../../grid/position/GridPositionSystem.js";
44
- import {Transform2GridPositionSystem} from "../../../../grid/transform2grid/Transform2GridPositionSystem.js";
43
+ import { Transform2GridPositionSystem } from "../../../../grid/transform2grid/Transform2GridPositionSystem.js";
45
44
  import InputControllerSystem from "../../../../input/ecs/systems/InputControllerSystem.js";
46
- import {InputSystem} from "../../../../input/ecs/systems/InputSystem.js";
47
- import {BehaviorSystem} from "../../../../intelligence/behavior/ecs/BehaviorSystem.js";
45
+ import { InputSystem } from "../../../../input/ecs/systems/InputSystem.js";
46
+ import { BehaviorSystem } from "../../../../intelligence/behavior/ecs/BehaviorSystem.js";
48
47
  import PathFollowingSystem from "../../../../navigation/ecs/path_following/PathFollowingSystem.js";
49
- import {SoundEmitterSystem} from "../../../../sound/ecs/emitter/SoundEmitterSystem.js";
48
+ import { SoundEmitterSystem } from "../../../../sound/ecs/emitter/SoundEmitterSystem.js";
50
49
  import SoundControllerSystem from "../../../../sound/ecs/SoundControllerSystem.js";
51
50
  import SoundListenerSystem from "../../../../sound/ecs/SoundListenerSystem.js";
52
51
  import AnimationControllerSystem from "../../../ecs/animation/AnimationControllerSystem.js";
53
- import {AnimationGraphSystem} from "../../../ecs/animation/animator/AnimationGraphSystem.js";
54
- import {CameraSystem} from "../../../ecs/camera/CameraSystem.js";
52
+ import { AnimationGraphSystem } from "../../../ecs/animation/animator/AnimationGraphSystem.js";
53
+ import { CameraSystem } from "../../../ecs/camera/CameraSystem.js";
55
54
  import TopDownCameraControllerSystem from "../../../ecs/camera/topdown/TopDownCameraControllerSystem.js";
56
- import {TopDownCameraLanderSystem} from "../../../ecs/camera/topdown/TopDownCameraLanderSystem.js";
55
+ import { TopDownCameraLanderSystem } from "../../../ecs/camera/topdown/TopDownCameraLanderSystem.js";
57
56
  import MeshHighlightSystem from "../../../ecs/highlight/system/MeshHighlightSystem.js";
58
57
  import LightSystem from "../../../ecs/light/LightSystem.js";
59
58
  import Mesh from "../../../ecs/mesh/Mesh.js";
60
- import {MeshSystem} from "../../../ecs/mesh/MeshSystem.js";
61
- import {PathDisplaySystem} from "../../../ecs/path/PathDisplaySystem.js";
59
+ import { MeshSystem } from "../../../ecs/mesh/MeshSystem.js";
60
+ import { PathDisplaySystem } from "../../../ecs/path/PathDisplaySystem.js";
62
61
  import Trail2DSystem from "../../../ecs/trail2d/Trail2DSystem.js";
63
62
  import WaterSystem from "../../../ecs/water/WaterSystem.js";
64
- import {load_and_set_cubemap_v0} from "../../../load_and_set_cubemap_v0.js";
65
- import {StandardFrameBuffers} from "../../../StandardFrameBuffers.js";
66
- import {Sampler2D} from "../../../texture/sampler/Sampler2D.js";
67
- import {HierarchicalZBuffer} from "./buffer/HierarchicalZBuffer.js";
68
- import {buildCanvasViewFromTexture} from "./buildCanvasViewFromTexture.js";
69
- import {BatchOcclusionQuery} from "./query/BatchOcclusionQuery.js";
63
+ import { load_and_set_cubemap_v0 } from "../../../load_and_set_cubemap_v0.js";
64
+ import { StandardFrameBuffers } from "../../../StandardFrameBuffers.js";
65
+ import { Sampler2D } from "../../../texture/sampler/Sampler2D.js";
66
+ import { HierarchicalZBuffer } from "./buffer/HierarchicalZBuffer.js";
67
+ import { buildCanvasViewFromTexture } from "./buildCanvasViewFromTexture.js";
68
+ import { BatchOcclusionQuery } from "./query/BatchOcclusionQuery.js";
70
69
 
71
70
  const engineHarness = new EngineHarness();
72
71
 
@@ -108,7 +107,6 @@ function makeConfig(engine) {
108
107
  new TerrainSystem(graphics, assetManager),
109
108
  new WaterSystem(graphics),
110
109
  new Trail2DSystem(engine),
111
- new Foliage2System(assetManager, graphics),
112
110
  new ViewportPositionSystem(graphics.viewport.size),
113
111
  new GridPosition2TransformSystem(),
114
112
  new Transform2GridPositionSystem(),
@@ -1,12 +1,13 @@
1
1
  import Army from "../../../../../model/game/ecs/component/army/Army.js";
2
- import {initializeGameBinarySerializationRegistry} from "../../../../../model/game/GameBinarySerializationRegistry.js";
3
- import {enableEditor} from "../../../../editor/enableEditor.js";
2
+ import {
3
+ initializeGameBinarySerializationRegistry
4
+ } from "../../../../../model/game/GameBinarySerializationRegistry.js";
5
+ import { enableEditor } from "../../../../editor/enableEditor.js";
4
6
  import Vector2 from "../../../core/geom/Vector2.js";
5
- import {ArrayBufferLoader} from "../../asset/loaders/ArrayBufferLoader.js";
6
- import {AttachmentSystem} from "../../ecs/attachment/AttachmentSystem.js";
7
- import {SerializationMetadata} from "../../ecs/components/SerializationMetadata.js";
7
+ import { ArrayBufferLoader } from "../../asset/loaders/ArrayBufferLoader.js";
8
+ import { AttachmentSystem } from "../../ecs/attachment/AttachmentSystem.js";
9
+ import { SerializationMetadata } from "../../ecs/components/SerializationMetadata.js";
8
10
  import Entity from "../../ecs/Entity.js";
9
- import {Foliage2System} from "../../ecs/foliage/ecs/Foliage2System.js";
10
11
  import GUIElement from "../../ecs/gui/GUIElement.js";
11
12
  import GUIElementSystem from "../../ecs/gui/GUIElementSystem.js";
12
13
  import HeadsUpDisplaySystem from "../../ecs/gui/hud/HeadsUpDisplaySystem.js";
@@ -16,27 +17,27 @@ import AnimationSystem from "../../ecs/systems/AnimationSystem.js";
16
17
  import TagSystem from "../../ecs/systems/TagSystem.js";
17
18
  import ClingToTerrainSystem from "../../ecs/terrain/ecs/cling/ClingToTerrainSystem.js";
18
19
  import TerrainSystem from "../../ecs/terrain/ecs/TerrainSystem.js";
19
- import {EngineConfiguration} from "../../EngineConfiguration.js";
20
- import {EngineHarness} from "../../EngineHarness.js";
20
+ import { EngineConfiguration } from "../../EngineConfiguration.js";
21
+ import { EngineHarness } from "../../EngineHarness.js";
21
22
  import InputControllerSystem from "../../input/ecs/systems/InputControllerSystem.js";
22
- import {InputSystem} from "../../input/ecs/systems/InputSystem.js";
23
- import {BehaviorSystem} from "../../intelligence/behavior/ecs/BehaviorSystem.js";
24
- import {loadSerializedScene} from "../../scene/SerializedScene.js";
25
- import {SoundEmitterSystem} from "../../sound/ecs/emitter/SoundEmitterSystem.js";
23
+ import { InputSystem } from "../../input/ecs/systems/InputSystem.js";
24
+ import { BehaviorSystem } from "../../intelligence/behavior/ecs/BehaviorSystem.js";
25
+ import { loadSerializedScene } from "../../scene/SerializedScene.js";
26
+ import { SoundEmitterSystem } from "../../sound/ecs/emitter/SoundEmitterSystem.js";
26
27
  import SoundControllerSystem from "../../sound/ecs/SoundControllerSystem.js";
27
28
  import SoundListenerSystem from "../../sound/ecs/SoundListenerSystem.js";
28
- import {CameraSystem} from "../ecs/camera/CameraSystem.js";
29
+ import { CameraSystem } from "../ecs/camera/CameraSystem.js";
29
30
  import TopDownCameraControllerSystem from "../ecs/camera/topdown/TopDownCameraControllerSystem.js";
30
31
  import MeshHighlightSystem from "../ecs/highlight/system/MeshHighlightSystem.js";
31
32
  import LightSystem from "../ecs/light/LightSystem.js";
32
- import {ShadedGeometrySystem} from "../ecs/mesh-v2/ShadedGeometrySystem.js";
33
+ import { ShadedGeometrySystem } from "../ecs/mesh-v2/ShadedGeometrySystem.js";
33
34
  import Mesh from "../ecs/mesh/Mesh.js";
34
- import {MeshSystem} from "../ecs/mesh/MeshSystem.js";
35
- import {PathDisplaySystem} from "../ecs/path/PathDisplaySystem.js";
35
+ import { MeshSystem } from "../ecs/mesh/MeshSystem.js";
36
+ import { PathDisplaySystem } from "../ecs/path/PathDisplaySystem.js";
36
37
  import Trail2DSystem from "../ecs/trail2d/Trail2DSystem.js";
37
38
  import WaterSystem from "../ecs/water/WaterSystem.js";
38
- import {ParticleEmitterSystem} from "../particles/ecs/ParticleEmitterSystem.js";
39
- import {buildCanvasViewFromTexture} from "../render/visibility/hiz/buildCanvasViewFromTexture.js";
39
+ import { ParticleEmitterSystem } from "../particles/ecs/ParticleEmitterSystem.js";
40
+ import { buildCanvasViewFromTexture } from "../render/visibility/hiz/buildCanvasViewFromTexture.js";
40
41
 
41
42
  const eh = new EngineHarness();
42
43
 
@@ -81,7 +82,6 @@ function makeConfig(engine) {
81
82
  new ClingToTerrainSystem(),
82
83
  new TerrainSystem(graphics, assetManager),
83
84
  new Trail2DSystem(engine),
84
- new Foliage2System(assetManager, graphics),
85
85
  new ViewportPositionSystem(graphics.viewport.size),
86
86
  new InputControllerSystem(devices),
87
87
  new InputSystem(devices),
@@ -0,0 +1,11 @@
1
+ /**
2
+ * Up, down, left, right
3
+ * @readonly
4
+ * @type {number[]}
5
+ */
6
+ export const ORTHOGONAL_NEIGHBOURHOOD_MASK = [
7
+ 0, -1,
8
+ -1, 0,
9
+ 1, 0,
10
+ 0, 1
11
+ ];
@@ -0,0 +1,8 @@
1
+ /**
2
+ * Convert decibel to percentage volume
3
+ * @param {number} dB
4
+ * @returns {number}
5
+ */
6
+ function dB2Volume(dB) {
7
+ return Math.pow(10, 0.05 * dB);
8
+ }
@@ -3,43 +3,25 @@
3
3
  */
4
4
 
5
5
 
6
+ import {EBBVHLeafProxy} from "../../../../core/bvh2/bvh3/EBBVHLeafProxy.js";
7
+ import {computeHashIntegerArray} from "../../../../core/collection/array/computeHashIntegerArray.js";
6
8
  import List from '../../../../core/collection/list/List.js';
9
+ import {aabb3_array_compute_from_sphere} from "../../../../core/geom/3d/aabb/aabb3_array_compute_from_sphere.js";
7
10
  import Vector1 from "../../../../core/geom/Vector1.js";
8
- import { SoundTrack } from "./SoundTrack.js";
9
- import { SoundEmitterFlags } from "./SoundEmitterFlags.js";
10
- import { SoundAttenuationFunction } from "./SoundAttenuationFunction.js";
11
- import {
12
- interpolate_irradiance_linear
13
- } from "../../../../core/math/physics/irradiance/interpolate_irradiance_linear.js";
11
+ import {interpolate_irradiance_linear} from "../../../../core/math/physics/irradiance/interpolate_irradiance_linear.js";
14
12
  import {
15
13
  interpolate_irradiance_lograrithmic
16
14
  } from "../../../../core/math/physics/irradiance/interpolate_irradiance_lograrithmic.js";
17
- import { SoundPanningModelType } from "./SoundPanningModelType.js";
18
- import { interpolate_irradiance_smith } from "../../../../core/math/physics/irradiance/interpolate_irradiance_smith.js";
19
- import { objectKeyByValue } from "../../../../core/model/object/objectKeyByValue.js";
20
- import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
21
- import { computeHashIntegerArray } from "../../../../core/collection/array/computeHashIntegerArray.js";
22
- import { computeHashFloat } from "../../../../core/primitives/numbers/computeHashFloat.js";
23
- import { compareStrings } from "../../../../core/primitives/strings/compareStrings.js";
24
- import { number_compare_ascending } from "../../../../core/primitives/numbers/number_compare_ascending.js";
25
-
26
- /**
27
- * Convert decibel to percentage volume
28
- * @param {number} dB
29
- * @returns {number}
30
- */
31
- function dB2Volume(dB) {
32
- return Math.pow(10, 0.05 * dB);
33
- }
34
-
35
- /**
36
- * Convert percentage volume to decibel
37
- * @param {number} volume
38
- * @returns {number}
39
- */
40
- function volume2dB(volume) {
41
- return 20 * Math.log10(volume);
42
- }
15
+ import {interpolate_irradiance_smith} from "../../../../core/math/physics/irradiance/interpolate_irradiance_smith.js";
16
+ import {objectKeyByValue} from "../../../../core/model/object/objectKeyByValue.js";
17
+ import {computeHashFloat} from "../../../../core/primitives/numbers/computeHashFloat.js";
18
+ import {number_compare_ascending} from "../../../../core/primitives/numbers/number_compare_ascending.js";
19
+ import {compareStrings} from "../../../../core/primitives/strings/compareStrings.js";
20
+ import {computeStringHash} from "../../../../core/primitives/strings/computeStringHash.js";
21
+ import {SoundAttenuationFunction} from "./SoundAttenuationFunction.js";
22
+ import {SoundEmitterFlags} from "./SoundEmitterFlags.js";
23
+ import {SoundPanningModelType} from "./SoundPanningModelType.js";
24
+ import {SoundTrack} from "./SoundTrack.js";
43
25
 
44
26
  const DEFAULT_DISTANCE_MIN = 1;
45
27
  const DEFAULT_DISTANCE_MAX = 10000;
@@ -50,92 +32,105 @@ const DEFAULT_CHANNEL = null;
50
32
  * @class
51
33
  */
52
34
  export class SoundEmitter {
35
+
36
+
37
+ /**
38
+ * @readonly
39
+ * @type {List<SoundTrack>}
40
+ */
41
+ tracks = new List();
42
+
53
43
  /**
54
44
  *
55
- * @constructor
45
+ * @type {String|SoundEmitterChannels|null}
56
46
  */
57
- constructor() {
47
+ channel = DEFAULT_CHANNEL;
58
48
 
59
- /**
60
- *
61
- * @type {List<SoundTrack>}
62
- */
63
- this.tracks = new List();
49
+ /**
50
+ *
51
+ * @type {number}
52
+ * @private
53
+ */
54
+ __distanceMin = 1;
64
55
 
65
- /**
66
- *
67
- * @type {String|SoundEmitterChannels|null}
68
- */
69
- this.channel = DEFAULT_CHANNEL;
56
+ /**
57
+ *
58
+ * @type {number}
59
+ * @private
60
+ */
61
+ __distanceMax = 10000;
70
62
 
71
- /**
72
- *
73
- * @type {number}
74
- * @private
75
- */
76
- this.__distanceMin = 1;
63
+ /**
64
+ * @deprecated
65
+ * @type {number}
66
+ * @private
67
+ */
68
+ __distanceRolloff = 1;
77
69
 
78
- /**
79
- *
80
- * @type {number}
81
- * @private
82
- */
83
- this.__distanceMax = 10000;
70
+ /**
71
+ * TODO add to binary serialization
72
+ * @type {SoundPanningModelType}
73
+ */
74
+ panningModel = SoundPanningModelType.HRTF;
75
+
76
+ /**
77
+ * Type of attenuation used for sound fall-off, this is only used if Attenuation flag is set
78
+ * @type {SoundAttenuationFunction|number}
79
+ */
80
+ attenuation = SoundAttenuationFunction.Smith;
81
+
82
+ /**
83
+ *
84
+ * @type {number|SoundEmitterFlags}
85
+ */
86
+ flags = 0;
84
87
 
88
+ /**
89
+ * @readonly
90
+ */
91
+ nodes = {
85
92
  /**
86
- * @deprecated
87
- * @type {number}
88
- * @private
93
+ * @type {GainNode}
89
94
  */
90
- this.__distanceRolloff = 1;
91
-
95
+ volume: null,
92
96
  /**
93
- * TODO add to binary serialization
94
- * @type {SoundPanningModelType}
97
+ * @type {PannerNode}
95
98
  */
96
- this.panningModel = SoundPanningModelType.HRTF;
97
-
99
+ panner: null,
98
100
  /**
99
- * Type of attenuation used for sound fall-off, this is only used if Attenuation flag is set
100
- * @type {SoundAttenuationFunction|number}
101
+ * @type {GainNode}
101
102
  */
102
- this.attenuation = SoundAttenuationFunction.Smith;
103
-
103
+ attenuation: null,
104
104
  /**
105
- *
106
- * @type {number|SoundEmitterFlags}
105
+ * One of the other nodes, depending on the configuration
106
+ * @type {AudioNode}
107
107
  */
108
- this.flags = 0;
108
+ endpoint: null
109
+ };
109
110
 
110
- const nodes = this.nodes = {
111
- /**
112
- * @type {GainNode}
113
- */
114
- volume: null,
115
- /**
116
- * @type {PannerNode}
117
- */
118
- panner: null,
119
- /**
120
- * @type {GainNode}
121
- */
122
- attenuation: null,
123
- /**
124
- * One of the other nodes, depending on the configuration
125
- * @type {AudioNode}
126
- */
127
- endpoint: null
128
- };
111
+ /**
112
+ *
113
+ * @type {Vector1}
114
+ */
115
+ volume = new Vector1(1);
129
116
 
130
- /**
131
- *
132
- * @type {Vector1}
133
- */
134
- this.volume = new Vector1(1);
117
+ /**
118
+ * @readonly
119
+ * @type {EBBVHLeafProxy}
120
+ */
121
+ bvh = new EBBVHLeafProxy();
135
122
 
136
- this.volume.onChanged.add(function (value) {
137
- if (nodes.volume !== null) {
138
- nodes.volume.gain.setValueAtTime(value, 0);
123
+ /**
124
+ *
125
+ * @constructor
126
+ */
127
+ constructor() {
128
+
129
+ this.volume.onChanged.add((value) => {
130
+ const volume_node = this.nodes.volume;
131
+
132
+ if (volume_node !== null) {
133
+ volume_node.gain.setValueAtTime(value, 0);
139
134
  }
140
135
  });
141
136
 
@@ -437,6 +432,37 @@ export class SoundEmitter {
437
432
  }
438
433
  }
439
434
 
435
+ /**
436
+ *
437
+ * @param {number} x
438
+ * @param {number} y
439
+ * @param {number} z
440
+ */
441
+ updatePosition(x, y, z) {
442
+ if (this.getFlag(SoundEmitterFlags.Spatialization)) {
443
+ //update position of the panner node
444
+ const nodes = this.nodes;
445
+
446
+ /**
447
+ *
448
+ * @type {PannerNode}
449
+ */
450
+ const panner = nodes.panner;
451
+
452
+ if (panner !== null) {
453
+ panner.setPosition(x, y, z);
454
+ }
455
+ }
456
+
457
+ const distanceMax = this.distanceMax;
458
+
459
+ const bounds = this.bvh.bounds;
460
+
461
+ aabb3_array_compute_from_sphere(bounds, 0, x, y, z, distanceMax);
462
+
463
+ this.bvh.write_bounds();
464
+ }
465
+
440
466
  /**
441
467
  *
442
468
  * @param {number} [duration] fade duration in seconds
@@ -1,8 +1,6 @@
1
- import { LeafNode } from "../../../../core/bvh2/LeafNode.js";
2
- import { SoundTrackNodes } from "./SoundTrackNodes.js";
3
- import { SoundEmitterFlags } from "./SoundEmitterFlags.js";
4
- import { SoundTrackFlags } from "./SoundTrackFlags.js";
5
- import { loadSoundTrackAsset } from "./loadSoundTrackAsset.js";
1
+ import {loadSoundTrackAsset} from "./loadSoundTrackAsset.js";
2
+ import {SoundTrackFlags} from "./SoundTrackFlags.js";
3
+ import {SoundTrackNodes} from "./SoundTrackNodes.js";
6
4
 
7
5
  export class SoundEmitterComponentContext {
8
6
  constructor() {
@@ -31,12 +29,6 @@ export class SoundEmitterComponentContext {
31
29
  */
32
30
  this.targetNode = null;
33
31
 
34
- /**
35
- *
36
- * @type {LeafNode}
37
- */
38
- this.leaf = new LeafNode(this, 0, 0, 0, 0, 0, 0);
39
-
40
32
  /**
41
33
  *
42
34
  * @type {boolean}
@@ -67,37 +59,7 @@ export class SoundEmitterComponentContext {
67
59
  const y = position.y;
68
60
  const z = position.z;
69
61
 
70
- if (emitter.getFlag(SoundEmitterFlags.Spatialization)) {
71
- //update position of the panner node
72
- const nodes = emitter.nodes;
73
-
74
- /**
75
- *
76
- * @type {PannerNode}
77
- */
78
- const panner = nodes.panner;
79
-
80
- if (panner !== null) {
81
- panner.setPosition(x, y, z);
82
- }
83
- }
84
-
85
- /**
86
- *
87
- * @type {LeafNode}
88
- */
89
- const bvhLeaf = this.leaf;
90
-
91
- const distanceMax = emitter.distanceMax;
92
-
93
- bvhLeaf.resize(
94
- x - distanceMax,
95
- y - distanceMax,
96
- z - distanceMax,
97
- x + distanceMax,
98
- y + distanceMax,
99
- z + distanceMax
100
- );
62
+ emitter.updatePosition(x, y, z);
101
63
  }
102
64
 
103
65
  /**