@woosh/meep-engine 2.43.3 → 2.43.5

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 (52) hide show
  1. package/core/binary/BinaryBuffer.js +13 -1
  2. package/core/binary/BitSet.js +2 -2
  3. package/core/collection/array/array_range_equal_strict.js +22 -0
  4. package/core/collection/map/AsyncMapWrapper.js +13 -1
  5. package/core/collection/map/CachedAsyncMap.js +9 -2
  6. package/core/collection/map/CachedAsyncMap.spec.js +47 -0
  7. package/core/color/sRGB_to_linear.js +9 -4
  8. package/core/geom/3d/plane/orient3d_fast.js +3 -0
  9. package/core/geom/3d/plane/orient3d_robust.js +41 -0
  10. package/core/geom/3d/sphere/harmonics/README.md +15 -0
  11. package/core/geom/3d/sphere/harmonics/sh3_add.js +21 -0
  12. package/core/geom/3d/sphere/harmonics/sh3_dering_optimize_positive.js +618 -0
  13. package/core/geom/3d/sphere/harmonics/sh3_sample_by_direction.js +49 -0
  14. package/core/geom/3d/sphere/harmonics/sh3_sample_irradiance_by_direction.js +53 -0
  15. package/core/geom/3d/tetrahedra/TetrahedralMesh.js +251 -68
  16. package/core/geom/3d/tetrahedra/TetrahedralMesh.spec.js +80 -3
  17. package/core/geom/3d/tetrahedra/build_tetrahedral_mesh_buffer_geometry.js +75 -0
  18. package/core/geom/3d/tetrahedra/delaunay/Cavity.js +5 -1
  19. package/core/geom/3d/tetrahedra/delaunay/compute_delaunay_tetrahedral_mesh.js +30 -31
  20. package/core/geom/3d/tetrahedra/delaunay/fill_in_a_cavity.js +54 -18
  21. package/core/geom/3d/tetrahedra/delaunay/push_boundary_with_validation.js +27 -0
  22. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity.js +89 -0
  23. package/core/geom/3d/tetrahedra/delaunay/{tetrahedral_mesh_walk_toward_cavity.js → tetrahedral_mesh_walk_towards_containing_tetrahedron.js} +15 -12
  24. package/core/geom/3d/tetrahedra/delaunay/validate_cavity_boundary.js +60 -0
  25. package/core/geom/3d/tetrahedra/{point_in_tetrahedron_circumsphere.js → in_sphere_fast.js} +2 -4
  26. package/core/geom/3d/tetrahedra/in_sphere_robust.js +53 -0
  27. package/core/geom/3d/tetrahedra/prototypeTetrahedraBuilder.js +44 -35
  28. package/core/geom/3d/tetrahedra/validate_tetrahedral_mesh.js +85 -38
  29. package/core/geom/3d/util/make_justified_point_grid.js +31 -0
  30. package/core/process/delay.js +5 -0
  31. package/editor/Editor.js +3 -0
  32. package/editor/ecs/component/editors/ecs/ParameterLookupTableEditor.js +195 -11
  33. package/editor/ecs/component/editors/ecs/ParameterTrackSetEditor.js +16 -0
  34. package/editor/ecs/component/editors/ecs/ParticleEmitterLayerEditor.js +4 -0
  35. package/engine/EngineHarness.js +11 -5
  36. package/engine/ecs/terrain/ecs/TerrainSystem.js +7 -1
  37. package/engine/ecs/transform/copy_three_transform.js +15 -0
  38. package/engine/graphics/ecs/light/Light.js +6 -1
  39. package/engine/graphics/ecs/light/LightSystem.d.ts +1 -1
  40. package/engine/graphics/ecs/mesh-v2/three_object_to_entity_composition.js +2 -17
  41. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +2 -2
  42. package/engine/graphics/micron/plugin/shaded_geometry/MicronShadedGeometryRenderAdapter.js +9 -1
  43. package/engine/graphics/sh3/LightProbeVolume.js +595 -0
  44. package/engine/graphics/sh3/SH3VisualisationMaterial.js +79 -0
  45. package/engine/graphics/sh3/prototypeSH3Probe.js +427 -0
  46. package/engine/graphics/sh3/visualise_probe.js +40 -0
  47. package/engine/graphics/texture/atlas/TextureAtlas.js +15 -3
  48. package/engine/intelligence/blackboard/AbstractBlackboard.d.ts +1 -1
  49. package/package.json +2 -1
  50. package/samples/terrain/from_image_2.js +127 -82
  51. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_compute_cavity2.js +0 -224
  52. package/core/geom/3d/tetrahedra/delaunay/tetrahedral_mesh_insert_point.js +0 -98
@@ -343,7 +343,7 @@ export class BinaryBuffer {
343
343
  *
344
344
  * @param {number} destination_offset starting index in the destination array
345
345
  * @param {number} length number of elements to read
346
- * @param {Uint32Array} destination
346
+ * @param {Uint32Array|number[]|ArrayLike<number>} destination
347
347
  */
348
348
  readUint32Array(destination, destination_offset, length) {
349
349
  for (let i = 0; i < length; i++) {
@@ -707,6 +707,18 @@ export class BinaryBuffer {
707
707
  this.position = end;
708
708
  }
709
709
 
710
+ /**
711
+ *
712
+ * @param {Uint32Array|number[]|ArrayLike<number>} source
713
+ * @param {number} source_offset
714
+ * @param {number} length
715
+ */
716
+ writeUint32Array(source, source_offset, length) {
717
+ for (let i = 0; i < length; i++) {
718
+ this.writeUint32(source[source_offset + i]);
719
+ }
720
+ }
721
+
710
722
  /**
711
723
  *
712
724
  * @param {Uint8Array|Uint8ClampedArray} array
@@ -403,9 +403,9 @@ BitSet.prototype.set = function (bitIndex, value) {
403
403
 
404
404
  if (bitIndex === this.__length - 1) {
405
405
  // trim down set size potentially
406
- const newLastSetBit = this.previousSetBit(bitIndex);
406
+ // const newLastSetBit = this.previousSetBit(bitIndex);
407
407
 
408
- this.__setLength(newLastSetBit + 1);
408
+ this.__setLength(bitIndex );
409
409
  }
410
410
  }
411
411
 
@@ -0,0 +1,22 @@
1
+ /**
2
+ * Checks that elements in supplied arrays are exactly equal within a certain range defined by a pair of offsets and element count (length)
3
+ * @template T
4
+ * @param {T[]} a
5
+ * @param {number} offset_a
6
+ * @param {T[]} b
7
+ * @param {number} offset_b
8
+ * @param {number} length
9
+ * @returns {boolean}
10
+ */
11
+ export function array_range_equal_strict(a, offset_a, b, offset_b, length) {
12
+
13
+ for (let i = 0; i < length; i++) {
14
+
15
+ if (a[offset_a + i] !== b[offset_b + i]) {
16
+ return false;
17
+ }
18
+
19
+ }
20
+
21
+ return true;
22
+ }
@@ -1,8 +1,20 @@
1
1
  import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
2
2
 
3
+ /**
4
+ * Wraps synchronous {@link Map}-implementing object
5
+ */
3
6
  export class AsyncMapWrapper extends AbstractAsyncMap {
4
- constructor(source) {
7
+ /**
8
+ *
9
+ * @param {Map} [source]
10
+ */
11
+ constructor(source = new Map()) {
5
12
  super();
13
+ /**
14
+ *
15
+ * @type {Map}
16
+ * @private
17
+ */
6
18
  this._source = source;
7
19
  }
8
20
 
@@ -1,10 +1,17 @@
1
1
  import { AbstractAsyncMap } from "./AbstractAsyncMap.js";
2
2
 
3
+ /**
4
+ * Two-tier key-value storage. Intended to accelerate slow asynchronous
5
+ * storage with a fast but limited (in space and reliability) cache in front.
6
+ *
7
+ * First tier (volatile) is considered to be fast an unreliable,
8
+ * whereas second tier (persisted) is considered to be reliable, but slow.
9
+ */
3
10
  export class CachedAsyncMap extends AbstractAsyncMap {
4
11
  /**
5
12
  *
6
- * @param {AbstractAsyncMap} volatile
7
- * @param {AbstractAsyncMap} persisted
13
+ * @param {AbstractAsyncMap} volatile data here may be lost at any point, this is our "cache"
14
+ * @param {AbstractAsyncMap} persisted data here is stored reliably
8
15
  */
9
16
  constructor(volatile, persisted) {
10
17
  super();
@@ -0,0 +1,47 @@
1
+ import { CachedAsyncMap } from "./CachedAsyncMap.js";
2
+ import { AsyncMapWrapper } from "./AsyncMapWrapper.js";
3
+
4
+ test("'get' retrieves data if it is available in volatile level", async () => {
5
+
6
+ const first = new Map();
7
+
8
+ const sut = new CachedAsyncMap(new AsyncMapWrapper(first), new AsyncMapWrapper());
9
+
10
+ first.set(1, 3);
11
+
12
+ expect(await sut.get(1)).toBe(3);
13
+ });
14
+
15
+ test("'get' retrieves data if it is available in persisted level", async () => {
16
+
17
+ const second = new Map();
18
+
19
+ const sut = new CachedAsyncMap(new AsyncMapWrapper(), new AsyncMapWrapper(second));
20
+
21
+ second.set(1, 3);
22
+
23
+ expect(await sut.get(1)).toBe(3);
24
+ });
25
+
26
+ test("'set' propagates data into volatile level", async () => {
27
+
28
+ const first = new Map();
29
+
30
+ const sut = new CachedAsyncMap(new AsyncMapWrapper(first), new AsyncMapWrapper());
31
+
32
+ await sut.set(1, 3);
33
+
34
+ expect(first.get(1)).toBe(3);
35
+ });
36
+
37
+
38
+ test("'set' propagates data into persisted level", async () => {
39
+
40
+ const second = new Map();
41
+
42
+ const sut = new CachedAsyncMap(new AsyncMapWrapper(), new AsyncMapWrapper(second));
43
+
44
+ await sut.set(1, 3);
45
+
46
+ expect(second.get(1)).toBe(3);
47
+ });
@@ -1,4 +1,9 @@
1
- function convert(c) {
1
+ /**
2
+ *
3
+ * @param {number} c
4
+ * @return {number|number}
5
+ */
6
+ export function convert_channel_sRGB_to_linear(c) {
2
7
  return (c < 0.04045) ? c * 0.0773993808 : Math.pow(c * 0.9478672986 + 0.0521327014, 2.4);
3
8
  }
4
9
 
@@ -10,7 +15,7 @@ function convert(c) {
10
15
  * @param {number} input_offset
11
16
  */
12
17
  export function sRGB_to_linear(output, output_offset, input, input_offset) {
13
- output[output_offset] = convert(input[input_offset]);
14
- output[output_offset + 1] = convert(input[input_offset + 1]);
15
- output[output_offset + 2] = convert(input[input_offset + 2]);
18
+ output[output_offset] = convert_channel_sRGB_to_linear(input[input_offset]);
19
+ output[output_offset + 1] = convert_channel_sRGB_to_linear(input[input_offset + 1]);
20
+ output[output_offset + 2] = convert_channel_sRGB_to_linear(input[input_offset + 2]);
16
21
  }
@@ -1,4 +1,6 @@
1
1
  /**
2
+ * Non-robust
3
+ *
2
4
  * Return a positive value if the point pd lies below the
3
5
  * plane passing through pa, pb, and pc; "below" is defined so
4
6
  * that pa, pb, and pc appear in counterclockwise order when
@@ -43,3 +45,4 @@ export function orient3d_fast(points, a, b, c, d) {
43
45
  + bdx * (cdy * adz - cdz * ady)
44
46
  + cdx * (ady * bdz - adz * bdy);
45
47
  }
48
+
@@ -0,0 +1,41 @@
1
+ import { orient3d } from "robust-predicates";
2
+
3
+ /**
4
+ *
5
+ * @param {number[]} points
6
+ * @param {number} a index of point a
7
+ * @param {number} b index of point b
8
+ * @param {number} c index of point c
9
+ * @param {number} d index of point d
10
+ * @returns {number}
11
+ */
12
+ export function orient3d_robust(
13
+ points,
14
+ a, b, c, d
15
+ ) {
16
+
17
+
18
+ const a3 = a * 3;
19
+ const b3 = b * 3;
20
+ const c3 = c * 3;
21
+ const d3 = d * 3;
22
+
23
+ const ax = points[a3];
24
+ const ay = points[a3 + 1];
25
+ const az = points[a3 + 2];
26
+
27
+ const bx = points[b3];
28
+ const by = points[b3 + 1];
29
+ const bz = points[b3 + 2];
30
+
31
+ const cx = points[c3];
32
+ const cy = points[c3 + 1];
33
+ const cz = points[c3 + 2];
34
+
35
+ const dx = points[d3];
36
+ const dy = points[d3 + 1];
37
+ const dz = points[d3 + 2];
38
+
39
+
40
+ return orient3d(ax, ay, az, bx, by, bz, cx, cy, cz, dx, dy, dz);
41
+ }
@@ -0,0 +1,15 @@
1
+ Tools for working with spherical harmonics.
2
+
3
+ Mostly intended for shading and global illumination.
4
+
5
+ ## De-ringing
6
+ There are basically 3 approaches,
7
+ * one is filtering using some kind of a smoothing function such as Lanczos
8
+ * Optimization of the polynomial (generally to remove negative values)
9
+ * Piece-wise reconstruction
10
+
11
+ ### References:
12
+
13
+ ---
14
+ * 2008 - GDC - Stupid Spherical Harmonics (SH) Tricks by Peter-Pike Sloan
15
+ * [Computing product of 2 sphecial harmonics](https://github.com/ruba/cortex-vfx/blob/c256b7274516a02fa64a0260351b86f1d6ebe8c2/include/IECore/SphericalHarmonicsAlgo.inl)
@@ -0,0 +1,21 @@
1
+ //
2
+
3
+ /**
4
+ * Add two spherical harmonics with 3 bands (9 coefficients)
5
+ *
6
+ * @param {number[]} result
7
+ * @param {number} result_offset
8
+ * @param {number[]} input_0
9
+ * @param {number} input_0_offset
10
+ * @param {number[]} input_1
11
+ * @param {number} input_1_offset
12
+ * @param {number} dimension_count
13
+ */
14
+ export function sh3_add(result, result_offset, input_0, input_0_offset, input_1, input_1_offset, dimension_count) {
15
+ const n = 9 * dimension_count;
16
+
17
+ for (let i = 0; i < n; i++) {
18
+ result[result_offset + i] = input_0[input_0_offset + i] + input_1[input_1_offset + i];
19
+ }
20
+
21
+ }