@woosh/meep-engine 2.33.57 → 2.33.61

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 (95) hide show
  1. package/core/bvh2/aabb3/AABB3.js +4 -1
  2. package/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +6 -6
  3. package/core/cache/Cache.js +7 -0
  4. package/core/collection/array/fastArrayEquals.js +17 -0
  5. package/core/collection/array/typed/is_typed_array_equals.js +58 -0
  6. package/core/collection/map/AbstractAsyncMap.js +30 -0
  7. package/core/collection/map/AsyncMapWrapper.js +16 -0
  8. package/core/collection/map/AsyncRemoteHashMap.js +358 -0
  9. package/core/collection/map/CachedAsyncMap.js +34 -0
  10. package/core/geom/3d/SurfacePoint3.js +44 -5
  11. package/core/geom/Vector2.d.ts +2 -0
  12. package/core/geom/Vector4.js +5 -5
  13. package/core/geom/packing/MaxRectangles.js +13 -4
  14. package/core/math/hash/murmur3_32.js +3 -3
  15. package/engine/animation/removeEntityGenericEffect.js +22 -31
  16. package/engine/asset/Asset.js +0 -45
  17. package/engine/asset/AssetDescription.js +51 -0
  18. package/engine/asset/AssetManager.d.ts +7 -0
  19. package/engine/asset/AssetManager.js +98 -2
  20. package/engine/asset/AssetTransformer.d.ts +5 -0
  21. package/engine/asset/AssetTransformer.js +15 -0
  22. package/engine/asset/loaders/GLTFAssetLoader.js +27 -25
  23. package/engine/asset/loaders/material/computeImageBitmapEquality.js +2 -2
  24. package/engine/asset/loaders/material/computeTextureEquality.js +2 -2
  25. package/engine/asset/loaders/material/computeTextureHash.js +7 -13
  26. package/engine/ecs/attachment/AttachmentSystem.js +18 -17
  27. package/engine/ecs/grid/HeightMap2NormalMap.js +1 -1
  28. package/engine/ecs/grid/NormalMap2AOMap.js +1 -1
  29. package/engine/ecs/gui/GUIElement.js +0 -106
  30. package/engine/ecs/gui/GUIElementSerializationAdapter.js +108 -0
  31. package/engine/ecs/gui/hud/HeadsUpDisplaySystem.js +60 -45
  32. package/engine/ecs/gui/position/ViewportPositionSystem.js +5 -5
  33. package/engine/ecs/parent/EntityNode.d.ts +20 -0
  34. package/engine/ecs/parent/EntityNode.js +284 -0
  35. package/engine/ecs/parent/FaceEditor.js +137 -0
  36. package/engine/ecs/parent/testCompositionEntityNode.js +153 -0
  37. package/engine/ecs/parent/testHuDPerf.js +123 -0
  38. package/engine/ecs/storage/binary/BinaryClassUpgrader.js +1 -0
  39. package/engine/ecs/terrain/ecs/Terrain.js +14 -5
  40. package/engine/ecs/util/removeComponentsExcept.js +3 -3
  41. package/engine/graphics/GraphicsEngine.js +4 -5
  42. package/engine/graphics/camera/testClippingPlaneComputation.js +0 -4
  43. package/engine/graphics/ecs/camera/topdown/TopDownCameraController.js +0 -1
  44. package/engine/graphics/ecs/camera/topdown/TopDownCameraController.spec.js +8 -0
  45. package/engine/graphics/ecs/light/LightSystem.js +1 -1
  46. package/engine/graphics/ecs/mesh/Mesh.js +5 -5
  47. package/engine/graphics/ecs/mesh/MeshSystem.js +12 -20
  48. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +29 -0
  49. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +158 -1
  50. package/engine/graphics/ecs/path/PathDisplaySystem.d.ts +3 -1
  51. package/engine/graphics/ecs/path/testPathDisplaySystem.js +0 -2
  52. package/engine/graphics/ecs/trail2d/Trail2D.js +35 -1
  53. package/engine/graphics/ecs/trail2d/Trail2DSystem.js +26 -19
  54. package/engine/graphics/ecs/trail2d/makeGradientTrail.js +68 -0
  55. package/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +55 -11
  56. package/engine/graphics/micron/convert_three_object_to_micron.js +24 -7
  57. package/engine/graphics/micron/plugin/MicronRenderPlugin.js +107 -4
  58. package/engine/graphics/micron/plugin/serialization/BufferGeometrySerializationAdapter.js +176 -0
  59. package/engine/graphics/micron/render/v1/MaterialContext.js +1 -0
  60. package/engine/graphics/particles/particular/engine/simulator/SimulationStepFixedPhysics.js +19 -3
  61. package/engine/graphics/particles/particular/engine/utils/volume/ParticleVolume.d.ts +2 -0
  62. package/engine/graphics/particles/particular/engine/utils/volume/prototypeParticleVolume.js +1 -4
  63. package/engine/graphics/render/buffer/buffers/prototypeNormalFrameBuffer.js +0 -2
  64. package/engine/graphics/render/buffer/simple-fx/DepthLimitedBlur.js +2 -2
  65. package/engine/graphics/render/forward_plus/plugin/ptototypeFPPlugin.js +0 -2
  66. package/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +3 -1
  67. package/engine/graphics/render/frame_graph/FrameGraphBuilder.js +36 -0
  68. package/engine/graphics/render/frame_graph/IRenderContext.js +8 -0
  69. package/engine/graphics/render/frame_graph/RenderPass.js +32 -0
  70. package/engine/graphics/render/frame_graph/RenderPassFlags.js +6 -0
  71. package/engine/graphics/render/frame_graph/RenderPassResources.js +15 -0
  72. package/engine/graphics/render/frame_graph/Resource.js +21 -0
  73. package/engine/graphics/render/frame_graph/ResourceReference.js +14 -0
  74. package/engine/graphics/render/frame_graph/TextureDescriptor.js +30 -0
  75. package/engine/graphics/render/frame_graph/UsageModeType.js +5 -0
  76. package/engine/graphics/render/frame_graph/sample/deferred/GBufferDrawPass.js +27 -0
  77. package/engine/graphics/render/frame_graph/sample/deferred/PresentPass.js +17 -0
  78. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +0 -2
  79. package/engine/graphics/render/webgpu/sample/_main.ts +650 -0
  80. package/engine/graphics/render/webgpu/sample/fragmentDeferredRendering.wgsl +67 -0
  81. package/engine/graphics/render/webgpu/sample/fragmentGBuffersDebugView.wgsl +38 -0
  82. package/engine/graphics/render/webgpu/sample/fragmentWriteGBuffers.wgsl +21 -0
  83. package/engine/graphics/render/webgpu/sample/lightUpdate.wgsl +34 -0
  84. package/engine/graphics/render/webgpu/sample/main.js +566 -0
  85. package/engine/graphics/render/webgpu/sample/vertexTextureQuad.wgsl +9 -0
  86. package/engine/graphics/render/webgpu/sample/vertexWriteGBuffers.wgsl +28 -0
  87. package/engine/graphics/shadows/ShadowMapRenderer.js +10 -4
  88. package/engine/graphics/shadows/testShadowMapRendering.js +0 -2
  89. package/engine/graphics/texture/sampler/Sampler2D.js +24 -45
  90. package/engine/{ecs/grid → graphics/texture/sampler}/sampler2DToFloat32Texture.js +1 -1
  91. package/engine/intelligence/behavior/ecs/WaitForEventBehavior.js +3 -0
  92. package/engine/save/storage/IndexedDBStorage.js +8 -1
  93. package/package.json +1 -1
  94. package/samples/terrain/main.js +117 -0
  95. package/engine/ecs/sockets/AttachmentSocketsSystem.js +0 -10
@@ -832,11 +832,14 @@ AABB3.prototype.intersectSpace = function (clippingPlanes) {
832
832
  AABB3.prototype.intersectFrustumDegree = function (frustum) {
833
833
  const planes = frustum.planes;
834
834
 
835
+ let i = 0;
835
836
  let result = 2;
836
- for (let i = 0; i < 6; i++) {
837
+ for (i = 0; i < 6; i++) {
837
838
 
838
839
  const plane = planes[i];
840
+
839
841
  const planeSide = this.computePlaneSide(plane);
842
+
840
843
  if (planeSide < 0) {
841
844
  return 0;
842
845
  } else if (planeSide === 0) {
@@ -22,19 +22,19 @@ export function traverseBinaryNodeUsingVisitor(node, visitor) {
22
22
 
23
23
  if (traverseDeeper !== false) {
24
24
 
25
- if (n.right !== null) {
25
+ if (n.left !== null) {
26
26
 
27
- // has a RIGHT child
27
+ // has a LEFT child
28
28
 
29
- stack[stackPointer++] = n.right;
29
+ stack[stackPointer++] = n.left;
30
30
 
31
31
  }
32
32
 
33
- if (n.left !== null) {
33
+ if (n.right !== null) {
34
34
 
35
- // has a LEFT child
35
+ // has a RIGHT child
36
36
 
37
- stack[stackPointer++] = n.left;
37
+ stack[stackPointer++] = n.right;
38
38
 
39
39
  }
40
40
 
@@ -7,6 +7,7 @@ import { CacheElement } from "./CacheElement.js";
7
7
  /**
8
8
  *
9
9
  * @template Key, Value
10
+ * @extends Map<Key,Value>
10
11
  */
11
12
  export class Cache {
12
13
  /**
@@ -430,3 +431,9 @@ export class Cache {
430
431
  this.weight = 0;
431
432
  }
432
433
  }
434
+
435
+ /**
436
+ * Shortcut for "map" compliance
437
+ * @type {Cache.put}
438
+ */
439
+ Cache.prototype.set = Cache.prototype.put;
@@ -0,0 +1,17 @@
1
+ import { isArrayEqualStrict } from "./isArrayEqualStrict.js";
2
+ import { is_typed_array_equals } from "./typed/is_typed_array_equals.js";
3
+
4
+ /**
5
+ *
6
+ * @param {number[]|Uint8Array} a
7
+ * @param {number[]|Uint8Array} b
8
+ */
9
+ export function fastArrayEquals(a, b) {
10
+ if (Array.isArray(a) || Array.isArray(b)) {
11
+ // not typed array
12
+ return isArrayEqualStrict(a, b);
13
+ }
14
+
15
+ // typed array, can do better
16
+ return is_typed_array_equals(a, b);
17
+ }
@@ -0,0 +1,58 @@
1
+ //
2
+ import { isArrayEqualStrict } from "../isArrayEqualStrict.js";
3
+
4
+ /**
5
+ *
6
+ * @param {Uint8Array} a
7
+ * @param {Uint8Array} b
8
+ * @returns {boolean}
9
+ */
10
+ export function is_typed_array_equals(a, b) {
11
+ const a_length = a.length;
12
+ const b_length = b.length;
13
+
14
+ if (a_length !== b_length) {
15
+ return false;
16
+ }
17
+
18
+ if (a_length < 128) {
19
+ // small array, do direct compare
20
+ return isArrayEqualStrict(a, b);
21
+ }
22
+
23
+ const byte_length = a.byteLength;
24
+
25
+ if (byte_length !== b.byteLength) {
26
+ return false;
27
+ }
28
+
29
+ const bytes_per_element = a.constructor.BYTES_PER_ELEMENT;
30
+
31
+ if (bytes_per_element !== b.constructor.BYTES_PER_ELEMENT) {
32
+ // incompatible constructors
33
+ return false;
34
+ }
35
+
36
+ const a_buffer = a.buffer;
37
+ const b_buffer = b.buffer;
38
+
39
+ // check if buffers are the same
40
+ if (a_buffer === b_buffer && a.byteOffset === b.byteOffset) {
41
+ // using the same buffer and pointing to the same range within it
42
+ return true;
43
+ }
44
+
45
+ let a_proxy = a;
46
+ let b_proxy = b;
47
+
48
+ if (bytes_per_element < 4 && byte_length % 4 === 0) {
49
+ // 4 byte alignment, can use uint32
50
+ a_proxy = new Uint32Array(a_buffer, a.byteOffset, byte_length / 4);
51
+ b_proxy = new Uint32Array(b_buffer, b.byteOffset, byte_length / 4);
52
+ } else if (bytes_per_element < 2 && byte_length % 2 === 0) {
53
+ a_proxy = new Uint16Array(a_buffer, a.byteOffset, byte_length / 2);
54
+ b_proxy = new Uint16Array(b_buffer, b.byteOffset, byte_length / 2);
55
+ }
56
+
57
+ return isArrayEqualStrict(a_proxy, b_proxy);
58
+ }
@@ -0,0 +1,30 @@
1
+ //
2
+
3
+
4
+ /**
5
+ * @template Key,Value
6
+ */
7
+ export class AbstractAsyncMap {
8
+ constructor() {
9
+
10
+ }
11
+
12
+ /**
13
+ *
14
+ * @param {Key} key
15
+ * @return {Promise<Value|undefined>}
16
+ */
17
+ async get(key) {
18
+ throw new Error('Not Implemented');
19
+ }
20
+
21
+ /**
22
+ *
23
+ * @param {Key} key
24
+ * @param {Value} value
25
+ * @return {Promise<void>}
26
+ */
27
+ async set(key, value) {
28
+ throw new Error('Not Implemented');
29
+ }
30
+ }
@@ -0,0 +1,16 @@
1
+ import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
2
+
3
+ export class AsyncMapWrapper extends AbstractAsyncMap {
4
+ constructor(source) {
5
+ super();
6
+ this._source = source;
7
+ }
8
+
9
+ async get(key) {
10
+ return this._source.get(key);
11
+ }
12
+
13
+ async set(key, value) {
14
+ this._source.set(key, value);
15
+ }
16
+ }
@@ -0,0 +1,358 @@
1
+ import { assert } from "../../assert.js";
2
+ import { BinaryBuffer } from "../../binary/BinaryBuffer.js";
3
+ import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
4
+
5
+ /**
6
+ * @template Key,Value
7
+ */
8
+ export class AsyncRemoteHashMap extends AbstractAsyncMap {
9
+
10
+ /**
11
+ *
12
+ * @param keyHashFunction
13
+ * @param keyEqualityFunction
14
+ * @param {BinaryClassSerializationAdapter} keySerializationAdapter
15
+ * @param {BinaryClassSerializationAdapter} valueSerializationAdapter
16
+ * @param storageKeyPrefix
17
+ * @param {Storage} storage
18
+ */
19
+ constructor({
20
+ keyHashFunction,
21
+ keyEqualityFunction,
22
+ keySerializationAdapter,
23
+ valueSerializationAdapter,
24
+ storageKeyPrefix,
25
+ storage
26
+ }) {
27
+ super();
28
+
29
+ assert.isString(storageKeyPrefix, 'storageKeyPrefix');
30
+
31
+ this._keyHashFunction = keyHashFunction;
32
+ this._keyEqualityFunction = keyEqualityFunction;
33
+ this._keySerializationAdapter = keySerializationAdapter;
34
+ this._valueSerializationAdapter = valueSerializationAdapter;
35
+ this._storageKeyPrefix = storageKeyPrefix;
36
+ this._storage = storage;
37
+
38
+ /**
39
+ *
40
+ * @type {Map<number,Promise>}
41
+ * @private
42
+ */
43
+ this._bucket_locks = new Map();
44
+ }
45
+
46
+ /**
47
+ *
48
+ * @param {Storage} storage
49
+ */
50
+ attach_storage(storage) {
51
+ this._storage = storage;
52
+ }
53
+
54
+ detach_storage() {
55
+ this._storage = null;
56
+ }
57
+
58
+ async __get_bucket_lock(hash) {
59
+ let source_lock = this._bucket_locks.get(hash);
60
+ if (source_lock === undefined) {
61
+ source_lock = Promise.resolve();
62
+ }
63
+
64
+ let is_resolved = false;
65
+ const lock_object = {
66
+ release() {
67
+ is_resolved = true;
68
+ }
69
+ };
70
+
71
+ const release_promise = new Promise((resolve, reject) => {
72
+ lock_object.release = resolve;
73
+
74
+ if (is_resolved) {
75
+ resolve();
76
+ }
77
+ });
78
+
79
+ const new_lock = source_lock.then(() => release_promise);
80
+
81
+ this._bucket_locks.set(hash, new_lock);
82
+
83
+ await source_lock;
84
+
85
+ return lock_object;
86
+ }
87
+
88
+ /**
89
+ * @param {number} hash
90
+ * @return {Promise<ArrayBuffer|undefined>}
91
+ * @private
92
+ */
93
+ __get_bucket_binary(hash) {
94
+ return this._storage.promiseLoadBinary(this.__compute_bucket_storage_key(hash)).catch(() => {
95
+ return undefined;
96
+ });
97
+ }
98
+
99
+ __compute_bucket_storage_key(hash) {
100
+ return `${this._storageKeyPrefix}/${hash}`;
101
+ }
102
+
103
+ /**
104
+ *
105
+ * @param {number} hash
106
+ * @param {ArrayBuffer} bucket
107
+ * @return {Promise}
108
+ * @private
109
+ */
110
+ __set_bucket_binary(hash, bucket) {
111
+ return this._storage.promiseStoreBinary(this.__compute_bucket_storage_key(hash), bucket);
112
+ }
113
+
114
+ /**
115
+ *
116
+ * @param {Key} key
117
+ * @param {Value|undefined} value
118
+ * @param {ArrayBuffer} buffer
119
+ * @return {ArrayBuffer}
120
+ * @private
121
+ */
122
+ __set_value_by_key_in_bucket(key, value, buffer) {
123
+ const source = new BinaryBuffer();
124
+ source.fromArrayBuffer(buffer);
125
+
126
+ const record_count = buffer.byteLength >= 2 ? source.readUint16() : 0;
127
+
128
+ let new_record_count = record_count;
129
+
130
+ // first attempt to find the key
131
+ const existing_value_address = this.__get_value_offset_from_bucket_by_key(key, buffer);
132
+
133
+ if (existing_value_address === -1) {
134
+ new_record_count++;
135
+ }
136
+
137
+ const destination = new BinaryBuffer();
138
+ destination.writeUint16(new_record_count);
139
+
140
+ let destination_data_offset = 2 + 16 * new_record_count;
141
+ let write_cursor = 0;
142
+ // copy old record over
143
+ for (let i = 0; i < record_count; i++) {
144
+ source.position = 2 + i * 16;
145
+
146
+ const key_position = source.readUint32();
147
+ const key_length = source.readUint32();
148
+ const value_position = source.readUint32();
149
+ const value_length = source.readUint32();
150
+
151
+ if (existing_value_address !== -1 && value_position === existing_value_address) {
152
+ // skip
153
+ continue;
154
+ }
155
+
156
+ // write key + value
157
+ destination.position = 2 + write_cursor * 16;
158
+
159
+ // write header section
160
+ destination.writeUint32(destination_data_offset);
161
+ destination.writeUint32(key_length);
162
+ destination.writeUint32(destination_data_offset + key_length);
163
+ destination.writeUint32(value_length);
164
+
165
+ destination.position = destination_data_offset;
166
+ source.position = key_position;
167
+ BinaryBuffer.copyBytes(source, destination, key_length);
168
+
169
+ destination_data_offset += key_length;
170
+
171
+ destination.position = destination_data_offset;
172
+ source.position = value_position;
173
+ BinaryBuffer.copyBytes(source, destination, value_length);
174
+
175
+ destination_data_offset += value_length;
176
+
177
+ write_cursor++;
178
+ }
179
+
180
+ const inserted_key_address = destination_data_offset;
181
+ const inserted_key_length = this.__encode_object(destination, inserted_key_address, key, this._keySerializationAdapter);
182
+
183
+ destination_data_offset += inserted_key_length;
184
+ const inserted_value_address = destination_data_offset;
185
+ const inserted_value_length = this.__encode_object(destination, inserted_value_address, value, this._valueSerializationAdapter);
186
+
187
+
188
+ // write section for the new value
189
+ destination.position = 2 + 16 * write_cursor;
190
+ destination.writeUint32(inserted_key_address);
191
+ destination.writeUint32(inserted_key_length);
192
+ destination.writeUint32(inserted_value_address);
193
+ destination.writeUint32(inserted_value_length);
194
+
195
+ // restore position
196
+ destination.position = inserted_value_address + inserted_value_length;
197
+
198
+ destination.trim();
199
+
200
+ return destination.data;
201
+ }
202
+
203
+ /**
204
+ *
205
+ * @param {Key} key
206
+ * @param {ArrayBuffer} buffer
207
+ * @return {number} -1 if not found, otherwise address within the buffer where the value can be read
208
+ * @private
209
+ */
210
+ __get_value_offset_from_bucket_by_key(key, buffer) {
211
+ const binary = new BinaryBuffer();
212
+ binary.fromArrayBuffer(buffer);
213
+
214
+ if (binary.length < 2) {
215
+ return -1;
216
+ }
217
+
218
+ const record_count = binary.readUint16();
219
+
220
+ if (record_count === 0) {
221
+ return -1;
222
+ }
223
+
224
+ const key_offsets = new Uint32Array(record_count);
225
+ const value_offsets = new Uint32Array(record_count);
226
+
227
+ // read record offsets
228
+ for (let i = 0; i < record_count; i++) {
229
+ const key_offset = binary.readUint32();
230
+ const key_length = binary.readUint32();
231
+
232
+ const value_offset = binary.readUint32();
233
+ const value_length = binary.readUint32();
234
+
235
+ key_offsets[i] = key_offset;
236
+ value_offsets[i] = value_offset;
237
+ }
238
+
239
+ // read key
240
+ for (let i = 0; i < record_count; i++) {
241
+ const key_address = key_offsets[i];
242
+
243
+ const stored_key = this.__decode_object(binary, key_address, this._keySerializationAdapter);
244
+
245
+ if (this._keyEqualityFunction(stored_key, key)) {
246
+ return value_offsets[i]
247
+ }
248
+ }
249
+
250
+ return -1;
251
+ }
252
+
253
+ /**
254
+ *
255
+ * @param {BinaryBuffer} buffer
256
+ * @param {number} address
257
+ * @param {BinaryClassSerializationAdapter} adapter
258
+ * @return {Value}
259
+ * @private
260
+ */
261
+ __decode_object(buffer, address, adapter) {
262
+
263
+ buffer.position = address;
264
+
265
+ const ValueKlass = adapter.getClass();
266
+
267
+ const value = new ValueKlass();
268
+
269
+ adapter.deserialize(buffer, value);
270
+
271
+ return value;
272
+ }
273
+
274
+ /**
275
+ * @template T
276
+ * @param {BinaryBuffer} buffer
277
+ * @param {number} address
278
+ * @param {T} value
279
+ * @param {BinaryClassSerializationAdapter} adapter
280
+ * @returns {number} bytes written
281
+ * @private
282
+ */
283
+ __encode_object(buffer, address, value, adapter) {
284
+ buffer.position = address;
285
+
286
+ adapter.serialize(buffer, value);
287
+
288
+ const bytes_written = buffer.position - address;
289
+
290
+ return bytes_written;
291
+ }
292
+
293
+ /**
294
+ *
295
+ * @param {BinaryBuffer} buffer
296
+ * @param {number} address
297
+ * @return {Value}
298
+ * @private
299
+ */
300
+ __decode_value(buffer, address) {
301
+ return this.__decode_object(buffer, address, this._valueSerializationAdapter);
302
+ }
303
+
304
+ /**
305
+ *
306
+ * @param {Key} key
307
+ * @return {Promise<Value|undefined>}
308
+ */
309
+ async get(key) {
310
+ // hash the key to identify bucket to load
311
+ const key_hash = this._keyHashFunction(key);
312
+
313
+ const lock = await this.__get_bucket_lock(key_hash);
314
+
315
+ const bucket_buffer = await this.__get_bucket_binary(key_hash);
316
+
317
+ lock.release();
318
+
319
+ if (bucket_buffer === undefined) {
320
+ return;
321
+ }
322
+
323
+ const value_address = this.__get_value_offset_from_bucket_by_key(key, bucket_buffer);
324
+
325
+ if (value_address === -1) {
326
+ return;
327
+ }
328
+
329
+ const binary = new BinaryBuffer();
330
+ binary.fromArrayBuffer(bucket_buffer);
331
+
332
+ return this.__decode_value(binary, value_address);
333
+ }
334
+
335
+ /**
336
+ *
337
+ * @param {Key} key
338
+ * @param {Value} value
339
+ * @return {Promise<void>}
340
+ */
341
+ async set(key, value) {
342
+ const key_hash = this._keyHashFunction(key);
343
+
344
+ const lock = await this.__get_bucket_lock(key_hash);
345
+
346
+ let bucket_buffer = await this.__get_bucket_binary(key_hash);
347
+
348
+ if (bucket_buffer === undefined) {
349
+ bucket_buffer = new ArrayBuffer(0);
350
+ }
351
+
352
+ const updated_buffer = this.__set_value_by_key_in_bucket(key, value, bucket_buffer);
353
+
354
+ await this.__set_bucket_binary(key_hash, updated_buffer);
355
+
356
+ lock.release();
357
+ }
358
+ }
@@ -0,0 +1,34 @@
1
+ import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
2
+
3
+ export class CachedAsyncMap extends AbstractAsyncMap {
4
+ /**
5
+ *
6
+ * @param {AbstractAsyncMap} volatile
7
+ * @param {AbstractAsyncMap} persisted
8
+ */
9
+ constructor(volatile, persisted) {
10
+ super();
11
+
12
+ this.__volatile = volatile;
13
+ this.__persisted = persisted;
14
+ }
15
+
16
+ async get(key) {
17
+ const volatile_value = await this.__volatile.get(key);
18
+
19
+ if (volatile_value !== undefined && volatile_value !== null) {
20
+ return volatile_value;
21
+ }
22
+
23
+ return await this.__persisted.get(key);
24
+ }
25
+
26
+ async set(key, value) {
27
+ const lock = this.__volatile.set(key, value);
28
+
29
+ // don't wait for completion on persisted
30
+ this.__persisted.set(key, value);
31
+
32
+ await lock;
33
+ }
34
+ }
@@ -1,5 +1,6 @@
1
1
  import Quaternion from "../Quaternion.js";
2
2
  import Vector3 from "../Vector3.js";
3
+ import { v3_length } from "../v3_length.js";
3
4
 
4
5
  const q = new Quaternion();
5
6
 
@@ -14,14 +15,52 @@ export class SurfacePoint3 {
14
15
 
15
16
  /**
16
17
  *
17
- * @param {THREE.Matrix4} matrix4
18
+ * @param {number[]|mat4|Float32Array} m4
18
19
  */
19
- applyMatrix4_three(matrix4) {
20
- this.position.applyMatrix4_three(matrix4);
20
+ applyMatrix4(m4) {
21
+ // transform position
22
+ const p = this.position;
23
+
24
+ const p_x = p.x;
25
+ const p_y = p.y;
26
+ const p_z = p.z;
27
+
28
+ const result_p_x = m4[0] * p_x + m4[4] * p_y + m4[8] * p_z + m4[12];
29
+ const result_p_y = m4[1] * p_x + m4[5] * p_y + m4[9] * p_z + m4[13];
30
+ const result_p_z = m4[2] * p_x + m4[6] * p_y + m4[10] * p_z + m4[14];
31
+
32
+ this.position.set(
33
+ result_p_x,
34
+ result_p_y,
35
+ result_p_z
36
+ );
37
+
38
+ // transform normal
39
+ const n = this.normal;
40
+
41
+ const n_x = n.x;
42
+ const n_y = n.y;
43
+ const n_z = n.z;
44
+
45
+ const result_n_x = m4[0] * n_x + m4[4] * n_y + m4[8] * n_z;
46
+ const result_n_y = m4[1] * n_x + m4[5] * n_y + m4[9] * n_z;
47
+ const result_n_z = m4[2] * n_x + m4[6] * n_y + m4[10] * n_z;
21
48
 
22
- q.setFromRotationMatrix(matrix4);
49
+ const normal_multiplier = 1 / v3_length(result_n_x, result_n_y, result_n_z);
23
50
 
24
- this.normal.applyQuaternion(q);
51
+ this.normal.set(
52
+ result_n_x * normal_multiplier,
53
+ result_n_y * normal_multiplier,
54
+ result_n_z * normal_multiplier,
55
+ );
56
+ }
57
+
58
+ /**
59
+ *
60
+ * @param {THREE.Matrix4} matrix4
61
+ */
62
+ applyMatrix4_three(matrix4) {
63
+ this.applyMatrix4(matrix4.elements);
25
64
  }
26
65
 
27
66
  /**
@@ -30,6 +30,8 @@ export default class Vector2 {
30
30
 
31
31
  copy(other: Vector2): void
32
32
 
33
+ clone(): Vector2
34
+
33
35
  distanceTo(other: Vector2): number
34
36
 
35
37
  isZero(): boolean
@@ -313,10 +313,10 @@ class Vector4 {
313
313
  const qw = q.w;
314
314
 
315
315
  // calculate quat * vec
316
- let ix = qw * x + qy * z - qz * y;
317
- let iy = qw * y + qz * x - qx * z;
318
- let iz = qw * z + qx * y - qy * x;
319
- let iw = -qx * x - qy * y - qz * z;
316
+ const ix = qw * x + qy * z - qz * y;
317
+ const iy = qw * y + qz * x - qx * z;
318
+ const iz = qw * z + qx * y - qy * x;
319
+ const iw = -qx * x - qy * y - qz * z;
320
320
 
321
321
  // calculate result * inverse quat
322
322
  const _x = ix * qw + iw * -qx + iy * -qz - iz * -qy;
@@ -425,7 +425,7 @@ class Vector4 {
425
425
  this.set(x, y, z, w);
426
426
  }
427
427
 
428
- *[ Symbol.iterator ]() {
428
+ * [Symbol.iterator]() {
429
429
 
430
430
  yield this.x;
431
431
  yield this.y;