@woosh/meep-engine 3.45.0 → 3.46.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 (216) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/package.json +1 -1
  3. package/src/core/assert.d.ts.map +1 -1
  4. package/src/core/assert.js +5 -1
  5. package/src/core/binary/hash/XXH128Hash.d.ts +1 -37
  6. package/src/core/binary/hash/XXH128Hash.d.ts.map +1 -1
  7. package/src/core/binary/hash/XXH128Hash.js +4 -55
  8. package/src/core/binary/hash/XXH3_SECRET.d.ts +1 -12
  9. package/src/core/binary/hash/XXH3_SECRET.d.ts.map +1 -1
  10. package/src/core/binary/hash/XXH3_SECRET.js +4 -25
  11. package/src/core/binary/hash/crc32.d.ts +1 -15
  12. package/src/core/binary/hash/crc32.d.ts.map +1 -1
  13. package/src/core/binary/hash/crc32.js +4 -96
  14. package/src/core/binary/hash/xxh3_128.d.ts +1 -9
  15. package/src/core/binary/hash/xxh3_128.d.ts.map +1 -1
  16. package/src/core/binary/hash/xxh3_128.js +4 -341
  17. package/src/core/binary/hash/xxh3_64.d.ts +1 -8
  18. package/src/core/binary/hash/xxh3_64.d.ts.map +1 -1
  19. package/src/core/binary/hash/xxh3_64.js +4 -241
  20. package/src/core/binary/hash/xxh3_common.d.ts +1 -223
  21. package/src/core/binary/hash/xxh3_common.d.ts.map +1 -1
  22. package/src/core/binary/hash/xxh3_common.js +90 -476
  23. package/src/core/collection/array/combine_hash.d.ts +6 -0
  24. package/src/core/collection/array/combine_hash.d.ts.map +1 -1
  25. package/src/core/collection/array/combine_hash.js +6 -0
  26. package/src/core/function/FunctionCompiler.js +2 -2
  27. package/src/core/geom/3d/mat4/m4_multiply.d.ts +3 -0
  28. package/src/core/geom/3d/mat4/m4_multiply.d.ts.map +1 -1
  29. package/src/core/geom/3d/mat4/m4_multiply.js +3 -0
  30. package/src/core/geom/3d/mat4/m4_multiply_f64.d.ts +30 -0
  31. package/src/core/geom/3d/mat4/m4_multiply_f64.d.ts.map +1 -0
  32. package/src/core/geom/3d/mat4/m4_multiply_f64.js +106 -0
  33. package/src/core/geom/ConicRay.js +2 -2
  34. package/src/core/geom/Vector4.d.ts.map +1 -1
  35. package/src/core/geom/Vector4.js +8 -5
  36. package/src/core/math/hash/XXH128Hash.d.ts +38 -0
  37. package/src/core/math/hash/XXH128Hash.d.ts.map +1 -0
  38. package/src/core/math/hash/XXH128Hash.js +55 -0
  39. package/src/core/math/hash/XXH3_SECRET.d.ts +13 -0
  40. package/src/core/math/hash/XXH3_SECRET.d.ts.map +1 -0
  41. package/src/core/math/hash/XXH3_SECRET.js +25 -0
  42. package/src/core/math/hash/crc32.d.ts +16 -0
  43. package/src/core/math/hash/crc32.d.ts.map +1 -0
  44. package/src/core/math/hash/crc32.js +96 -0
  45. package/src/core/math/hash/xxh3_128.d.ts +10 -0
  46. package/src/core/math/hash/xxh3_128.d.ts.map +1 -0
  47. package/src/core/math/hash/xxh3_128.js +341 -0
  48. package/src/core/math/hash/xxh3_64.d.ts +9 -0
  49. package/src/core/math/hash/xxh3_64.d.ts.map +1 -0
  50. package/src/core/math/hash/xxh3_64.js +241 -0
  51. package/src/core/math/hash/xxh3_common.d.ts +224 -0
  52. package/src/core/math/hash/xxh3_common.d.ts.map +1 -0
  53. package/src/core/math/hash/xxh3_common.js +476 -0
  54. package/src/core/math/lookup/ParameterLookupTable.js +2 -2
  55. package/src/core/model/node-graph/node/NodeInstancePortReference.js +2 -2
  56. package/src/core/model/reactive/model/ReactiveBinaryExpression.js +2 -2
  57. package/src/core/model/reactive/model/terminal/ReactiveReference.js +2 -2
  58. package/src/engine/asset/AssetDescription.js +2 -2
  59. package/src/engine/ecs/animation/Animation.js +2 -2
  60. package/src/engine/ecs/animation/AnimationClip.d.ts.map +1 -1
  61. package/src/engine/ecs/animation/AnimationClip.js +7 -5
  62. package/src/engine/ecs/gui/GUIElement.d.ts.map +1 -1
  63. package/src/engine/ecs/gui/GUIElement.js +7 -5
  64. package/src/engine/ecs/gui/hud/HeadsUpDisplay.js +2 -2
  65. package/src/engine/ecs/gui/position/ViewportPosition.d.ts.map +1 -1
  66. package/src/engine/ecs/gui/position/ViewportPosition.js +11 -7
  67. package/src/engine/ecs/transform/Transform64.d.ts +1 -1
  68. package/src/engine/ecs/transform/Transform64.d.ts.map +1 -1
  69. package/src/engine/ecs/transform/Transform64.js +5 -4
  70. package/src/engine/graphics/ecs/animation/animator/AnimationClip.d.ts.map +1 -1
  71. package/src/engine/graphics/ecs/animation/animator/AnimationClip.js +8 -5
  72. package/src/engine/graphics/ecs/animation/animator/AnimationClipDefinition.js +2 -2
  73. package/src/engine/graphics/ecs/animation/animator/AnimationNotification.js +2 -2
  74. package/src/engine/graphics/ecs/animation/animator/AnimationNotificationDefinition.js +2 -2
  75. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationGraphDefinition.js +2 -2
  76. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationStateDefinition.js +2 -2
  77. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.d.ts.map +1 -1
  78. package/src/engine/graphics/ecs/animation/animator/graph/definition/AnimationTransitionDefinition.js +8 -5
  79. package/src/engine/graphics/ecs/decal/v2/Decal.d.ts.map +1 -1
  80. package/src/engine/graphics/ecs/decal/v2/Decal.js +9 -8
  81. package/src/engine/graphics/render/frame_graph/resource/TextureResourceDescriptor.d.ts.map +1 -1
  82. package/src/engine/graphics/render/frame_graph/resource/TextureResourceDescriptor.js +9 -6
  83. package/src/engine/graphics3/ParticipatingMedia.js +204 -204
  84. package/src/engine/graphics3/animation/AnimationClips.d.ts +5 -0
  85. package/src/engine/graphics3/animation/AnimationClips.d.ts.map +1 -1
  86. package/src/engine/graphics3/animation/AnimationClips.js +5 -0
  87. package/src/engine/grid/obstacle/GridObstacle.js +2 -2
  88. package/src/engine/intelligence/behavior/selector/WeightedElement.js +2 -2
  89. package/src/engine/interpolation/Interpolated.js +2 -2
  90. package/src/engine/physics/cloth/ecs/Cloth.d.ts.map +1 -1
  91. package/src/engine/physics/cloth/ecs/Cloth.js +7 -5
  92. package/src/engine/physics/cloth/ecs/ClothCollider.d.ts.map +1 -1
  93. package/src/engine/physics/cloth/ecs/ClothCollider.js +7 -5
  94. package/src/engine/physics/cloth/ecs/ClothDynamics.d.ts.map +1 -1
  95. package/src/engine/physics/cloth/ecs/ClothDynamics.js +20 -11
  96. package/src/engine/physics/fluid/FluidField.d.ts.map +1 -1
  97. package/src/engine/physics/fluid/FluidField.js +7 -5
  98. package/src/engine/physics/fluid/ecs/FluidComponent.d.ts.map +1 -1
  99. package/src/engine/physics/fluid/ecs/FluidComponent.js +19 -11
  100. package/src/engine/physics/fluid/effector/AbstractFluidEffector.d.ts +2 -2
  101. package/src/engine/physics/fluid/effector/AbstractFluidEffector.js +2 -2
  102. package/src/engine/physics/fluid/effector/GlobalFluidEffector.d.ts.map +1 -1
  103. package/src/engine/physics/fluid/effector/GlobalFluidEffector.js +11 -7
  104. package/src/engine/physics/fluid/effector/ImpulseFluidEffector.d.ts.map +1 -1
  105. package/src/engine/physics/fluid/effector/ImpulseFluidEffector.js +11 -7
  106. package/src/engine/physics/fluid/effector/WakeFluidEffector.d.ts.map +1 -1
  107. package/src/engine/physics/fluid/effector/WakeFluidEffector.js +16 -9
  108. package/src/engine/sound/ecs/audio/AudioEmitter.d.ts.map +1 -1
  109. package/src/engine/sound/ecs/audio/AudioEmitter.js +12 -7
  110. package/src/engine/sound/ecs/trigger/AudioEventTrigger.d.ts.map +1 -1
  111. package/src/engine/sound/ecs/trigger/AudioEventTrigger.js +192 -191
  112. package/src/engine/sound/simulation/core/AcousticMedium.js +2 -2
  113. package/src/engine/sound/simulation/definition/AcousticDirectivity.js +2 -2
  114. package/src/engine/sound/simulation/definition/AcousticMaterial.d.ts.map +1 -1
  115. package/src/engine/sound/simulation/definition/AcousticMaterial.js +11 -7
  116. package/src/engine/sound/sopra/definition/BusDefinition.d.ts.map +1 -1
  117. package/src/engine/sound/sopra/definition/BusDefinition.js +5 -4
  118. package/src/engine/sound/sopra/definition/DuckingRule.d.ts.map +1 -1
  119. package/src/engine/sound/sopra/definition/DuckingRule.js +7 -5
  120. package/src/engine/sound/sopra/definition/EventDescription.d.ts.map +1 -1
  121. package/src/engine/sound/sopra/definition/EventDescription.js +23 -13
  122. package/src/engine/sound/sopra/definition/MixerSnapshot.js +2 -2
  123. package/src/engine/sound/sopra/definition/ParameterDefinition.d.ts.map +1 -1
  124. package/src/engine/sound/sopra/definition/ParameterDefinition.js +7 -5
  125. package/src/engine/sound/sopra/definition/clip/AbstractAudioClip.js +2 -2
  126. package/src/engine/sound/sopra/definition/clip/BlendContainerAudioClip.d.ts.map +1 -1
  127. package/src/engine/sound/sopra/definition/clip/BlendContainerAudioClip.js +4 -3
  128. package/src/engine/sound/sopra/definition/clip/ContainerAudioClip.js +2 -2
  129. package/src/engine/sound/sopra/definition/clip/RandomContainerAudioClip.js +3 -3
  130. package/src/engine/sound/sopra/definition/clip/SampleAudioClip.d.ts.map +1 -1
  131. package/src/engine/sound/sopra/definition/clip/SampleAudioClip.js +16 -9
  132. package/src/engine/sound/sopra/definition/clip/SilenceAudioClip.js +2 -2
  133. package/src/engine/sound/sopra/definition/clip/SwitchContainerAudioClip.d.ts +1 -1
  134. package/src/engine/sound/sopra/definition/clip/SwitchContainerAudioClip.d.ts.map +1 -1
  135. package/src/engine/sound/sopra/definition/clip/SwitchContainerAudioClip.js +2 -2
  136. package/src/engine/sound/sopra/definition/effect/CompressorEffect.d.ts.map +1 -1
  137. package/src/engine/sound/sopra/definition/effect/CompressorEffect.js +7 -5
  138. package/src/engine/sound/sopra/definition/effect/EqEffect.d.ts.map +1 -1
  139. package/src/engine/sound/sopra/definition/effect/EqEffect.js +8 -5
  140. package/src/engine/sound/sopra/definition/effect/ReverbEffect.js +2 -2
  141. package/src/engine/sound/sopra/legacy/SoundEmitter.d.ts.map +1 -1
  142. package/src/engine/sound/sopra/legacy/SoundEmitter.js +357 -352
  143. package/src/engine/sound/sopra/legacy/SoundTrack.d.ts.map +1 -1
  144. package/src/engine/sound/sopra/legacy/SoundTrack.js +281 -278
  145. package/src/format/image/png/PNGReader.js +644 -644
  146. package/src/format/image/png/crc32.d.ts +1 -1
  147. package/src/format/image/png/crc32.js +7 -8
  148. package/src/shade/descriptor/binding/BindGroupLayoutDescriptor.js +2 -2
  149. package/src/shade/descriptor/binding/BindGroupLayoutEntry.d.ts.map +1 -1
  150. package/src/shade/descriptor/binding/BindGroupLayoutEntry.js +12 -8
  151. package/src/shade/descriptor/binding/StorageTextureBindingLayout.js +2 -2
  152. package/src/shade/descriptor/binding/TextureBindingLayout.js +2 -2
  153. package/src/shade/descriptor/blend/BlendComponent.js +2 -2
  154. package/src/shade/descriptor/pipeline/PipelineDescriptorBase.js +2 -2
  155. package/src/shade/descriptor/pipeline/PipelineLayoutDescriptor.js +2 -2
  156. package/src/shade/descriptor/pipeline/ProgrammableStage.js +2 -2
  157. package/src/shade/descriptor/pipeline/compute/ComputePipelineDescriptor.js +2 -2
  158. package/src/shade/descriptor/pipeline/render/ColorTargetState.js +2 -2
  159. package/src/shade/descriptor/pipeline/render/FragmentState.js +2 -2
  160. package/src/shade/descriptor/pipeline/render/PrimitiveState.js +2 -2
  161. package/src/shade/descriptor/pipeline/render/RenderPipelineDescriptor.d.ts.map +1 -1
  162. package/src/shade/descriptor/pipeline/render/RenderPipelineDescriptor.js +8 -5
  163. package/src/shade/descriptor/pipeline/render/VertexAttribute.js +2 -2
  164. package/src/shade/descriptor/texture/SamplerDescriptor.d.ts.map +1 -1
  165. package/src/shade/descriptor/texture/SamplerDescriptor.js +20 -12
  166. package/src/shade/descriptor/texture/TextureDescriptor.d.ts.map +1 -1
  167. package/src/shade/descriptor/texture/TextureDescriptor.js +11 -7
  168. package/src/shade/device/graph/BufferResourceDescriptor.d.ts.map +1 -1
  169. package/src/shade/device/graph/BufferResourceDescriptor.js +196 -193
  170. package/src/shade/device/graph/TextureResourceDescriptor.d.ts.map +1 -1
  171. package/src/shade/device/graph/TextureResourceDescriptor.js +178 -173
  172. package/src/shade/device/timing/profile/sgpt_read_header.js +1 -1
  173. package/src/shade/device/timing/profile/sgpt_read_records.js +1 -1
  174. package/src/shade/device/timing/profile/sgpt_write_header.js +1 -1
  175. package/src/shade/device/timing/profile/sgpt_write_record.js +1 -1
  176. package/src/shade/renderer/binding/BufferBinding.js +2 -2
  177. package/src/shade/renderer/camera/Camera.js +2 -2
  178. package/src/shade/renderer/geometry/Attribute.js +2 -2
  179. package/src/shade/renderer/geometry/Geometry.js +2 -2
  180. package/src/shade/renderer/geometry/geometry_deduplicate_vertices.js +2 -2
  181. package/src/shade/renderer/geometry/meshlet/MeshletBatch.js +2 -2
  182. package/src/shade/renderer/geometry/virtual/format/checksum/vgeo_compute_asset_id.js +13 -13
  183. package/src/shade/renderer/geometry/virtual/format/checksum/vgeo_compute_directory_block_checksum.js +41 -41
  184. package/src/shade/renderer/geometry/virtual/format/checksum/vgeo_compute_frame_checksum.js +41 -41
  185. package/src/shade/renderer/geometry/virtual/format/checksum/vgeo_compute_header_checksum.js +25 -25
  186. package/src/shade/renderer/material/StandardShadeMaterial.d.ts.map +1 -1
  187. package/src/shade/renderer/material/StandardShadeMaterial.js +13 -8
  188. package/src/shade/renderer/scene/optimization/geometry/internal/triangle_fingerprint_stream.d.ts.map +1 -1
  189. package/src/shade/renderer/scene/optimization/geometry/internal/triangle_fingerprint_stream.js +14 -5
  190. package/src/shade/renderer/scene/optimization/sampler2d_from_image_bitmap.js +1 -1
  191. package/src/shade/renderer/shader/type/WGSLStructField.js +2 -2
  192. package/src/shade/renderer/shader/type/WebGPUArray.js +2 -2
  193. package/src/shade/renderer/shader/type/WebGPUStruct.d.ts.map +1 -1
  194. package/src/shade/renderer/shader/type/WebGPUStruct.js +9 -6
  195. package/src/shade/renderer/texture/ShadeTexture.d.ts.map +1 -1
  196. package/src/shade/renderer/texture/ShadeTexture.js +17 -10
  197. package/src/shade/renderer/texture/mipmaps/WebGPUMipmapGenerator.js +2 -2
  198. package/src/shade/renderer/water/surface/chunk_water_surface_sample.d.ts +4 -4
  199. package/src/shade/renderer/water/surface/chunk_water_surface_sample.js +6 -6
  200. package/src/shade/renderer/water/surface/particles/GPUWaterParticles.d.ts.map +1 -1
  201. package/src/shade/renderer/water/surface/particles/GPUWaterParticles.js +46 -55
  202. package/src/shade/renderer/water/surface/particles/WATER_PARTICLE_STRUCT.d.ts +3 -3
  203. package/src/shade/renderer/water/surface/particles/WATER_PARTICLE_STRUCT.d.ts.map +1 -1
  204. package/src/shade/renderer/water/surface/particles/WATER_PARTICLE_STRUCT.js +14 -4
  205. package/src/shade/renderer/water/surface/particles/chunk_water_particle.d.ts +10 -1
  206. package/src/shade/renderer/water/surface/particles/chunk_water_particle.d.ts.map +1 -1
  207. package/src/shade/renderer/water/surface/particles/chunk_water_particle.js +82 -40
  208. package/src/shade/renderer/water/surface/particles/chunk_water_particle_step.d.ts +4 -1
  209. package/src/shade/renderer/water/surface/particles/chunk_water_particle_step.d.ts.map +1 -1
  210. package/src/shade/renderer/water/surface/particles/chunk_water_particle_step.js +8 -4
  211. package/src/shade/renderer/water/surface/particles/shader_water_particles.d.ts +98 -86
  212. package/src/shade/renderer/water/surface/particles/shader_water_particles.d.ts.map +1 -1
  213. package/src/shade/renderer/water/surface/particles/shader_water_particles.js +440 -298
  214. package/src/view/common/HTMLElementCacheKey.d.ts.map +1 -1
  215. package/src/view/common/HTMLElementCacheKey.js +4 -3
  216. package/src/view/minimap/MinimapMarker.js +2 -2
@@ -1,352 +1,357 @@
1
- import { combine_hash } from "../../../../core/collection/array/combine_hash.js";
2
- import List from '../../../../core/collection/list/List.js';
3
- import Vector1 from "../../../../core/geom/Vector1.js";
4
- import { objectKeyByValue } from "../../../../core/model/object/objectKeyByValue.js";
5
- import { computeHashFloat } from "../../../../core/primitives/numbers/computeHashFloat.js";
6
- import { number_compare_ascending } from "../../../../core/primitives/numbers/number_compare_ascending.js";
7
- import { compareStrings } from "../../../../core/primitives/strings/compareStrings.js";
8
- import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
9
- import { SoundAttenuationFunction } from "./SoundAttenuationFunction.js";
10
- import { SoundEmitterFlags } from "./SoundEmitterFlags.js";
11
- import { SoundPanningModelType } from "./SoundPanningModelType.js";
12
- import { SoundTrack } from "./SoundTrack.js";
13
-
14
- const DEFAULT_DISTANCE_MIN = 1;
15
- const DEFAULT_DISTANCE_MAX = 10000;
16
-
17
- const DEFAULT_CHANNEL = null;
18
-
19
- /**
20
- * @deprecated Frozen legacy reader — superseded by the native {@link AudioEmitter}, which owns a sopra
21
- * `EventDescription` directly. Data only: no system links it and nothing plays it. It survives so that
22
- * saves written before the native audio path still deserialize, and so
23
- * {@link convertLegacySoundComponents} can turn what they carry into authored sopra events. Do not
24
- * author new content with it.
25
- * @class
26
- */
27
- export class SoundEmitter {
28
-
29
-
30
- /**
31
- * @readonly
32
- * @type {List<SoundTrack>}
33
- */
34
- tracks = new List();
35
-
36
- /**
37
- * Free-string mixer channel name. Resolved against the live bus set by
38
- * {@link convertLegacySoundComponents}, which falls back to `effects` for a name the mixer no
39
- * longer has — sopra's bus lookup throws on an unknown id.
40
- * @type {String|null}
41
- */
42
- channel = DEFAULT_CHANNEL;
43
-
44
- /**
45
- *
46
- * @type {number}
47
- * @private
48
- */
49
- __distanceMin = 1;
50
-
51
- /**
52
- *
53
- * @type {number}
54
- * @private
55
- */
56
- __distanceMax = 10000;
57
-
58
- /**
59
- * TODO add to binary serialization
60
- * @type {SoundPanningModelType}
61
- */
62
- panningModel = SoundPanningModelType.HRTF;
63
-
64
- /**
65
- * Type of attenuation used for sound fall-off, this is only used if Attenuation flag is set
66
- * @type {SoundAttenuationFunction|number}
67
- */
68
- attenuation = SoundAttenuationFunction.Smith;
69
-
70
- /**
71
- *
72
- * @type {number|SoundEmitterFlags}
73
- */
74
- flags = 0;
75
-
76
- /**
77
- *
78
- * @type {Vector1}
79
- */
80
- volume = new Vector1(1);
81
-
82
- /**
83
- *
84
- * @param {SoundEmitter} other
85
- * @returns number
86
- */
87
- compare(other) {
88
- const tracks = this.tracks.compare(other.tracks);
89
-
90
- if (tracks !== 0) {
91
- return tracks;
92
- }
93
-
94
- const channel = compareStrings(this.channel, other.channel);
95
-
96
- if (channel !== 0) {
97
- return channel;
98
- }
99
-
100
- const distanceMin = number_compare_ascending(this.__distanceMin, other.__distanceMin);
101
-
102
- if (distanceMin !== 0) {
103
- return distanceMin;
104
- }
105
- const distanceMax = number_compare_ascending(this.__distanceMax, other.__distanceMax);
106
-
107
- if (distanceMax !== 0) {
108
- return distanceMax;
109
- }
110
-
111
- const panningModel = number_compare_ascending(this.panningModel, other.panningModel);
112
-
113
- if (panningModel !== 0) {
114
- return panningModel;
115
- }
116
-
117
- const attenuation = number_compare_ascending(this.attenuation, other.attenuation);
118
-
119
- if (attenuation !== 0) {
120
- return attenuation;
121
- }
122
-
123
- const flags = number_compare_ascending(this.flags, other.flags);
124
-
125
- if (flags !== 0) {
126
- return flags;
127
- }
128
-
129
- const volume = number_compare_ascending(this.volume.getValue(), other.volume.getValue());
130
-
131
- if (volume !== 0) {
132
- return volume;
133
- }
134
-
135
-
136
- return 0;
137
- }
138
-
139
-
140
- /**
141
- *
142
- * @param {number|SoundEmitterFlags} flag
143
- * @returns {void}
144
- */
145
- setFlag(flag) {
146
- this.flags |= flag;
147
- }
148
-
149
- /**
150
- *
151
- * @param {number|SoundEmitterFlags} flag
152
- * @returns {void}
153
- */
154
- clearFlag(flag) {
155
- this.flags &= ~flag;
156
- }
157
-
158
- /**
159
- *
160
- * @param {number|SoundEmitterFlags} flag
161
- * @param {boolean} value
162
- */
163
- writeFlag(flag, value) {
164
- if (value) {
165
- this.setFlag(flag);
166
- } else {
167
- this.clearFlag(flag);
168
- }
169
- }
170
-
171
- /**
172
- *
173
- * @param {number|SoundEmitterFlags} flag
174
- * @returns {boolean}
175
- */
176
- getFlag(flag) {
177
- return (this.flags & flag) === flag;
178
- }
179
-
180
-
181
- /**
182
- * @deprecated
183
- * @param {boolean} v
184
- */
185
- set isPositioned(v) {
186
- this.writeFlag(SoundEmitterFlags.Spatialization, v);
187
- }
188
-
189
- /**
190
- * @deprecated
191
- * @return {boolean}
192
- */
193
- get isPositioned() {
194
- return this.getFlag(SoundEmitterFlags.Spatialization);
195
- }
196
-
197
- /**
198
- * @returns {boolean}
199
- * @param {SoundEmitter} other
200
- */
201
- equals(other) {
202
- return this.channel === other.channel
203
- && this.flags === other.flags
204
- && this.__distanceMin === other.__distanceMin
205
- && this.__distanceMax === other.__distanceMax
206
- && this.attenuation === other.attenuation
207
- && this.tracks.equals(other.tracks)
208
- ;
209
- }
210
-
211
- /**
212
- *
213
- * @return {number}
214
- */
215
- hash() {
216
- return combine_hash(
217
- computeStringHash(this.channel),
218
- this.flags,
219
- computeHashFloat(this.__distanceMin),
220
- computeHashFloat(this.__distanceMax),
221
- this.attenuation,
222
- this.tracks.hash()
223
- );
224
- }
225
-
226
- /**
227
- *
228
- * @returns {number}
229
- */
230
- get distanceMin() {
231
- return this.__distanceMin;
232
- }
233
-
234
- /**
235
- * @param {number} v
236
- */
237
- set distanceMin(v) {
238
- this.__distanceMin = v;
239
- }
240
-
241
- /**
242
- *
243
- * @returns {number}
244
- */
245
- get distanceMax() {
246
- return this.__distanceMax;
247
- }
248
-
249
- /**
250
- * @param {number} v
251
- */
252
- set distanceMax(v) {
253
- this.__distanceMax = v;
254
- }
255
-
256
- toJSON() {
257
- return {
258
- isPositioned: this.getFlag(SoundEmitterFlags.Spatialization),
259
- isAttenuated: this.getFlag(SoundEmitterFlags.Attenuation),
260
- channel: this.channel,
261
- volume: this.volume.toJSON(),
262
- tracks: this.tracks.toJSON(),
263
- distanceMin: this.distanceMin,
264
- distanceMax: this.distanceMax,
265
- attenuation: objectKeyByValue(SoundAttenuationFunction, this.attenuation),
266
- panningModel: objectKeyByValue(SoundPanningModelType, this.panningModel)
267
- };
268
- }
269
-
270
- fromJSON(json) {
271
- if (json.isPositioned !== undefined) {
272
- this.writeFlag(SoundEmitterFlags.Spatialization, json.isPositioned);
273
- } else {
274
- this.clearFlag(SoundEmitterFlags.Spatialization);
275
- }
276
-
277
- if (json.channel !== undefined) {
278
- this.channel = json.channel;
279
- } else {
280
- this.channel = DEFAULT_CHANNEL;
281
- }
282
-
283
- if (json.volume !== undefined) {
284
- this.volume.fromJSON(json.volume);
285
- }
286
-
287
- if (typeof json.distanceMin === "number") {
288
- this.distanceMin = json.distanceMin;
289
- } else {
290
- this.distanceMin = DEFAULT_DISTANCE_MIN;
291
- }
292
-
293
- if (typeof json.distanceMax === "number") {
294
- this.distanceMax = json.distanceMax;
295
- } else {
296
- this.distanceMax = DEFAULT_DISTANCE_MAX;
297
- }
298
-
299
- if (typeof json.isAttenuated === "boolean") {
300
- this.writeFlag(SoundEmitterFlags.Attenuation, json.isAttenuated);
301
- } else {
302
- this.setFlag(SoundEmitterFlags.Attenuation);
303
- }
304
-
305
- if (typeof json.attenuation === "string") {
306
- const attenuation = SoundAttenuationFunction[json.attenuation];
307
-
308
- if (attenuation === undefined) {
309
- throw new Error(`Unknown attenuation type '${json.attenuation}', valid types are: ${Object.keys(SoundAttenuationFunction)}`);
310
- }
311
-
312
- this.attenuation = attenuation;
313
- } else {
314
- this.attenuation = SoundAttenuationFunction.Linear;
315
- }
316
-
317
- //tracks
318
- if (json.tracks !== undefined) {
319
- this.tracks.fromJSON(json.tracks, SoundTrack);
320
- }
321
-
322
- if (json.panningModel === undefined) {
323
- this.panningModel = SoundPanningModelType.HRTF;
324
- } else {
325
- const model = SoundPanningModelType[json.panningModel];
326
-
327
- if (model === undefined) {
328
- throw new Error(`Unknown panning model '${json.panningModel}', valid types are: ${Object.keys(SoundPanningModelType)}`);
329
- }
330
-
331
- this.panningModel = model;
332
- }
333
- }
334
-
335
-
336
- /**
337
- *
338
- * @param json
339
- * @returns {SoundEmitter}
340
- */
341
- static fromJSON(json) {
342
- const result = new SoundEmitter();
343
-
344
- result.fromJSON(json);
345
-
346
- return result;
347
- }
348
- }
349
-
350
- SoundEmitter.typeName = "SoundEmitter";
351
-
352
-
1
+ import { hash_mix2 } from "../../../../core/math/hash/hash_mix2.js";
2
+ import { hash_mix3 } from "../../../../core/math/hash/hash_mix3.js";
3
+ import List from '../../../../core/collection/list/List.js';
4
+ import Vector1 from "../../../../core/geom/Vector1.js";
5
+ import { objectKeyByValue } from "../../../../core/model/object/objectKeyByValue.js";
6
+ import { computeHashFloat } from "../../../../core/primitives/numbers/computeHashFloat.js";
7
+ import { number_compare_ascending } from "../../../../core/primitives/numbers/number_compare_ascending.js";
8
+ import { compareStrings } from "../../../../core/primitives/strings/compareStrings.js";
9
+ import { computeStringHash } from "../../../../core/primitives/strings/computeStringHash.js";
10
+ import { SoundAttenuationFunction } from "./SoundAttenuationFunction.js";
11
+ import { SoundEmitterFlags } from "./SoundEmitterFlags.js";
12
+ import { SoundPanningModelType } from "./SoundPanningModelType.js";
13
+ import { SoundTrack } from "./SoundTrack.js";
14
+
15
+ const DEFAULT_DISTANCE_MIN = 1;
16
+ const DEFAULT_DISTANCE_MAX = 10000;
17
+
18
+ const DEFAULT_CHANNEL = null;
19
+
20
+ /**
21
+ * @deprecated Frozen legacy reader — superseded by the native {@link AudioEmitter}, which owns a sopra
22
+ * `EventDescription` directly. Data only: no system links it and nothing plays it. It survives so that
23
+ * saves written before the native audio path still deserialize, and so
24
+ * {@link convertLegacySoundComponents} can turn what they carry into authored sopra events. Do not
25
+ * author new content with it.
26
+ * @class
27
+ */
28
+ export class SoundEmitter {
29
+
30
+
31
+ /**
32
+ * @readonly
33
+ * @type {List<SoundTrack>}
34
+ */
35
+ tracks = new List();
36
+
37
+ /**
38
+ * Free-string mixer channel name. Resolved against the live bus set by
39
+ * {@link convertLegacySoundComponents}, which falls back to `effects` for a name the mixer no
40
+ * longer has — sopra's bus lookup throws on an unknown id.
41
+ * @type {String|null}
42
+ */
43
+ channel = DEFAULT_CHANNEL;
44
+
45
+ /**
46
+ *
47
+ * @type {number}
48
+ * @private
49
+ */
50
+ __distanceMin = 1;
51
+
52
+ /**
53
+ *
54
+ * @type {number}
55
+ * @private
56
+ */
57
+ __distanceMax = 10000;
58
+
59
+ /**
60
+ * TODO add to binary serialization
61
+ * @type {SoundPanningModelType}
62
+ */
63
+ panningModel = SoundPanningModelType.HRTF;
64
+
65
+ /**
66
+ * Type of attenuation used for sound fall-off, this is only used if Attenuation flag is set
67
+ * @type {SoundAttenuationFunction|number}
68
+ */
69
+ attenuation = SoundAttenuationFunction.Smith;
70
+
71
+ /**
72
+ *
73
+ * @type {number|SoundEmitterFlags}
74
+ */
75
+ flags = 0;
76
+
77
+ /**
78
+ *
79
+ * @type {Vector1}
80
+ */
81
+ volume = new Vector1(1);
82
+
83
+ /**
84
+ *
85
+ * @param {SoundEmitter} other
86
+ * @returns number
87
+ */
88
+ compare(other) {
89
+ const tracks = this.tracks.compare(other.tracks);
90
+
91
+ if (tracks !== 0) {
92
+ return tracks;
93
+ }
94
+
95
+ const channel = compareStrings(this.channel, other.channel);
96
+
97
+ if (channel !== 0) {
98
+ return channel;
99
+ }
100
+
101
+ const distanceMin = number_compare_ascending(this.__distanceMin, other.__distanceMin);
102
+
103
+ if (distanceMin !== 0) {
104
+ return distanceMin;
105
+ }
106
+ const distanceMax = number_compare_ascending(this.__distanceMax, other.__distanceMax);
107
+
108
+ if (distanceMax !== 0) {
109
+ return distanceMax;
110
+ }
111
+
112
+ const panningModel = number_compare_ascending(this.panningModel, other.panningModel);
113
+
114
+ if (panningModel !== 0) {
115
+ return panningModel;
116
+ }
117
+
118
+ const attenuation = number_compare_ascending(this.attenuation, other.attenuation);
119
+
120
+ if (attenuation !== 0) {
121
+ return attenuation;
122
+ }
123
+
124
+ const flags = number_compare_ascending(this.flags, other.flags);
125
+
126
+ if (flags !== 0) {
127
+ return flags;
128
+ }
129
+
130
+ const volume = number_compare_ascending(this.volume.getValue(), other.volume.getValue());
131
+
132
+ if (volume !== 0) {
133
+ return volume;
134
+ }
135
+
136
+
137
+ return 0;
138
+ }
139
+
140
+
141
+ /**
142
+ *
143
+ * @param {number|SoundEmitterFlags} flag
144
+ * @returns {void}
145
+ */
146
+ setFlag(flag) {
147
+ this.flags |= flag;
148
+ }
149
+
150
+ /**
151
+ *
152
+ * @param {number|SoundEmitterFlags} flag
153
+ * @returns {void}
154
+ */
155
+ clearFlag(flag) {
156
+ this.flags &= ~flag;
157
+ }
158
+
159
+ /**
160
+ *
161
+ * @param {number|SoundEmitterFlags} flag
162
+ * @param {boolean} value
163
+ */
164
+ writeFlag(flag, value) {
165
+ if (value) {
166
+ this.setFlag(flag);
167
+ } else {
168
+ this.clearFlag(flag);
169
+ }
170
+ }
171
+
172
+ /**
173
+ *
174
+ * @param {number|SoundEmitterFlags} flag
175
+ * @returns {boolean}
176
+ */
177
+ getFlag(flag) {
178
+ return (this.flags & flag) === flag;
179
+ }
180
+
181
+
182
+ /**
183
+ * @deprecated
184
+ * @param {boolean} v
185
+ */
186
+ set isPositioned(v) {
187
+ this.writeFlag(SoundEmitterFlags.Spatialization, v);
188
+ }
189
+
190
+ /**
191
+ * @deprecated
192
+ * @return {boolean}
193
+ */
194
+ get isPositioned() {
195
+ return this.getFlag(SoundEmitterFlags.Spatialization);
196
+ }
197
+
198
+ /**
199
+ * @returns {boolean}
200
+ * @param {SoundEmitter} other
201
+ */
202
+ equals(other) {
203
+ return this.channel === other.channel
204
+ && this.flags === other.flags
205
+ && this.__distanceMin === other.__distanceMin
206
+ && this.__distanceMax === other.__distanceMax
207
+ && this.attenuation === other.attenuation
208
+ && this.tracks.equals(other.tracks)
209
+ ;
210
+ }
211
+
212
+ /**
213
+ *
214
+ * @return {number}
215
+ */
216
+ hash() {
217
+ return hash_mix2(
218
+ hash_mix3(
219
+ hash_mix3(
220
+ computeStringHash(this.channel),
221
+ this.flags,
222
+ computeHashFloat(this.__distanceMin)
223
+ ),
224
+ computeHashFloat(this.__distanceMax),
225
+ this.attenuation
226
+ ),
227
+ this.tracks.hash()
228
+ );
229
+ }
230
+
231
+ /**
232
+ *
233
+ * @returns {number}
234
+ */
235
+ get distanceMin() {
236
+ return this.__distanceMin;
237
+ }
238
+
239
+ /**
240
+ * @param {number} v
241
+ */
242
+ set distanceMin(v) {
243
+ this.__distanceMin = v;
244
+ }
245
+
246
+ /**
247
+ *
248
+ * @returns {number}
249
+ */
250
+ get distanceMax() {
251
+ return this.__distanceMax;
252
+ }
253
+
254
+ /**
255
+ * @param {number} v
256
+ */
257
+ set distanceMax(v) {
258
+ this.__distanceMax = v;
259
+ }
260
+
261
+ toJSON() {
262
+ return {
263
+ isPositioned: this.getFlag(SoundEmitterFlags.Spatialization),
264
+ isAttenuated: this.getFlag(SoundEmitterFlags.Attenuation),
265
+ channel: this.channel,
266
+ volume: this.volume.toJSON(),
267
+ tracks: this.tracks.toJSON(),
268
+ distanceMin: this.distanceMin,
269
+ distanceMax: this.distanceMax,
270
+ attenuation: objectKeyByValue(SoundAttenuationFunction, this.attenuation),
271
+ panningModel: objectKeyByValue(SoundPanningModelType, this.panningModel)
272
+ };
273
+ }
274
+
275
+ fromJSON(json) {
276
+ if (json.isPositioned !== undefined) {
277
+ this.writeFlag(SoundEmitterFlags.Spatialization, json.isPositioned);
278
+ } else {
279
+ this.clearFlag(SoundEmitterFlags.Spatialization);
280
+ }
281
+
282
+ if (json.channel !== undefined) {
283
+ this.channel = json.channel;
284
+ } else {
285
+ this.channel = DEFAULT_CHANNEL;
286
+ }
287
+
288
+ if (json.volume !== undefined) {
289
+ this.volume.fromJSON(json.volume);
290
+ }
291
+
292
+ if (typeof json.distanceMin === "number") {
293
+ this.distanceMin = json.distanceMin;
294
+ } else {
295
+ this.distanceMin = DEFAULT_DISTANCE_MIN;
296
+ }
297
+
298
+ if (typeof json.distanceMax === "number") {
299
+ this.distanceMax = json.distanceMax;
300
+ } else {
301
+ this.distanceMax = DEFAULT_DISTANCE_MAX;
302
+ }
303
+
304
+ if (typeof json.isAttenuated === "boolean") {
305
+ this.writeFlag(SoundEmitterFlags.Attenuation, json.isAttenuated);
306
+ } else {
307
+ this.setFlag(SoundEmitterFlags.Attenuation);
308
+ }
309
+
310
+ if (typeof json.attenuation === "string") {
311
+ const attenuation = SoundAttenuationFunction[json.attenuation];
312
+
313
+ if (attenuation === undefined) {
314
+ throw new Error(`Unknown attenuation type '${json.attenuation}', valid types are: ${Object.keys(SoundAttenuationFunction)}`);
315
+ }
316
+
317
+ this.attenuation = attenuation;
318
+ } else {
319
+ this.attenuation = SoundAttenuationFunction.Linear;
320
+ }
321
+
322
+ //tracks
323
+ if (json.tracks !== undefined) {
324
+ this.tracks.fromJSON(json.tracks, SoundTrack);
325
+ }
326
+
327
+ if (json.panningModel === undefined) {
328
+ this.panningModel = SoundPanningModelType.HRTF;
329
+ } else {
330
+ const model = SoundPanningModelType[json.panningModel];
331
+
332
+ if (model === undefined) {
333
+ throw new Error(`Unknown panning model '${json.panningModel}', valid types are: ${Object.keys(SoundPanningModelType)}`);
334
+ }
335
+
336
+ this.panningModel = model;
337
+ }
338
+ }
339
+
340
+
341
+ /**
342
+ *
343
+ * @param json
344
+ * @returns {SoundEmitter}
345
+ */
346
+ static fromJSON(json) {
347
+ const result = new SoundEmitter();
348
+
349
+ result.fromJSON(json);
350
+
351
+ return result;
352
+ }
353
+ }
354
+
355
+ SoundEmitter.typeName = "SoundEmitter";
356
+
357
+