@woosh/meep-engine 2.33.5 → 2.33.10

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 (116) hide show
  1. package/core/binary/BinaryBuffer.js +26 -2
  2. package/core/bvh2/LeafNode.js +6 -1
  3. package/core/bvh2/aabb3/AABB3.js +17 -0
  4. package/core/collection/RingBuffer.js +40 -10
  5. package/core/collection/array/typed/typed_array_copy.js +2 -2
  6. package/core/collection/set/compute_set_difference.js +32 -0
  7. package/core/collection/set/compute_set_intersection.js +22 -0
  8. package/core/collection/set/set_remove.js +15 -0
  9. package/core/collection/table/DataType2TypedArrayConstructorMapping.js +2 -0
  10. package/core/collection/table/DataTypeByteSizes.js +21 -0
  11. package/core/collection/table/RowFirstTable.js +1 -88
  12. package/core/collection/table/RowFirstTable.spec.js +3 -1
  13. package/core/collection/table/RowFirstTableSpec.js +1 -19
  14. package/core/collection/table/computeDataTypeByIndex.js +21 -0
  15. package/core/collection/table/deserializeRowFirstTable.js +48 -0
  16. package/core/collection/table/serializeRowFirstTable.js +27 -0
  17. package/core/color/Color.js +1 -0
  18. package/core/color/ColorUtils.js +12 -3
  19. package/core/geom/3d/aabb/aabb3_compute_projected_area.js +5 -4
  20. package/core/geom/3d/aabb/aabb3_from_min_max.js +15 -0
  21. package/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +96 -0
  22. package/{engine/graphics/micron/render/v1 → core/geom/3d}/apply_mat4_transform_to_v3_array.js +0 -0
  23. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.js +3 -3
  24. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_cone_of_2_cones.spec.js +1 -1
  25. package/{engine/graphics/micron/build/bounds → core/geom/3d}/compute_bounding_sphere_of_2_spheres.js +3 -3
  26. package/{engine/graphics/micron/util → core/geom/3d}/encode_unit3_hemioct.js +0 -0
  27. package/core/geom/3d/frustum/array_normalize_plane.js +25 -0
  28. package/core/geom/3d/frustum/array_setFromProjectionMatrix.js +60 -0
  29. package/{engine/graphics/micron/util → core/geom/3d}/unit_hemioct.spec.js +1 -1
  30. package/{engine/graphics/micron/build → core}/graph/MultiNode.js +0 -0
  31. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.js +2 -2
  32. package/{engine/graphics/micron/build → core}/graph/SquareMatrix.spec.js +1 -1
  33. package/{engine/graphics/micron/build → core}/graph/WeightedEdge.js +1 -1
  34. package/{engine/graphics/micron/build → core}/graph/build_face_graph_from_mesh.js +2 -2
  35. package/{engine/graphics/micron/build/clustering → core/graph}/cluster_mesh_metis.js +2 -6
  36. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.js +1 -1
  37. package/{engine/graphics/micron/build → core}/graph/coarsen_graph.spec.js +1 -1
  38. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.js +0 -0
  39. package/{engine/graphics/micron/build → core}/graph/eigen/eigen.spec.js +1 -1
  40. package/{engine/graphics/micron/build/hierarchy → core/graph/eigen}/eigen_values_find_spectral_gap.js +0 -0
  41. package/{engine/graphics/micron/build → core}/graph/graph_adjacency_matrix.js +0 -0
  42. package/{engine/graphics/micron/build → core}/graph/graph_compute_disconnected_clusters.js +0 -0
  43. package/{engine/graphics/micron/build → core}/graph/graph_degree_matrix.js +0 -0
  44. package/{engine/graphics/micron/build → core}/graph/graph_k_means_cluster.js +5 -5
  45. package/{engine/graphics/micron/build → core}/graph/graph_laplacian_matrix.js +1 -1
  46. package/{engine/graphics/micron/build → core}/graph/metis/metis.js +2 -2
  47. package/{engine/graphics/micron/build → core}/graph/metis/metis_options.js +0 -0
  48. package/{engine/graphics/micron/build → core}/graph/mn_graph_collapse_weighted_edge.js +0 -0
  49. package/core/process/undo/ActionProcessor.d.ts +2 -0
  50. package/core/process/undo/ActionProcessor.js +59 -1
  51. package/core/process/undo/ActionProcessor.spec.js +59 -0
  52. package/core/process/undo/Mark.js +2 -1
  53. package/engine/Engine.d.ts +2 -0
  54. package/engine/EngineHarness.js +4 -4
  55. package/engine/asset/loaders/material/bitmap2sampler_gl.js +19 -0
  56. package/engine/asset/loaders/material/computeImageBitmapEquality.js +7 -19
  57. package/engine/ecs/foliage/InstancedFoliage.js +3 -5
  58. package/engine/ecs/fow/serialization/FogOfWarSerializationAdapter.js +2 -1
  59. package/engine/ecs/transform/Transform.js +2 -1
  60. package/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +22 -37
  61. package/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +155 -0
  62. package/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +68 -0
  63. package/engine/graphics/ecs/mesh-v2/prototypeShadedGeometry.js +31 -0
  64. package/engine/graphics/{micron → geometry}/aabb3_to_buffer_geometry.js +0 -0
  65. package/engine/graphics/{micron/build → geometry/buffered}/compute_buffer_geometry_byte_size.js +0 -0
  66. package/engine/graphics/geometry/instancing/InstancedMeshGroup.js +25 -16
  67. package/engine/graphics/material/SplatMaterial.js +4 -97
  68. package/engine/graphics/micron/build/buildMicronGeometryFromBufferGeometry.js +2 -6
  69. package/engine/graphics/micron/build/clustering/build_clustering_2.js +2 -2
  70. package/engine/graphics/micron/build/clustering/build_leaf_patches_metis.js +1 -1
  71. package/engine/graphics/micron/build/fill_patch_geometry_data.js +2 -0
  72. package/engine/graphics/micron/build/hierarchy/buildAbstractPatchHierarchy.js +3 -3
  73. package/engine/graphics/micron/build/hierarchy/build_intermediate_patch_topology.js +0 -72
  74. package/engine/graphics/micron/build/hierarchy/build_merge_graph.js +2 -2
  75. package/engine/graphics/micron/build/hierarchy/computePatchMergeScore.js +3 -3
  76. package/engine/graphics/micron/build/hierarchy/merge_patches.js +6 -3
  77. package/engine/graphics/micron/build/hierarchy/metis_cluster_clusters.js +1 -1
  78. package/engine/graphics/micron/build/hierarchy/optimize_graph_partitioning_balance.js +1 -1
  79. package/engine/graphics/micron/build/hierarchy/patch_combine.js +2 -2
  80. package/engine/graphics/micron/build/hierarchy/qvdr_build_simplified_clusters.js +2 -1
  81. package/engine/graphics/micron/format/MicronGeometry.js +12 -0
  82. package/engine/graphics/micron/format/MicronGeometryBufferAttributeSpec.js +1 -1
  83. package/engine/graphics/micron/format/MicronGeometryPatch.js +17 -9
  84. package/engine/graphics/micron/format/MicronVertexDataSpec.js +25 -3
  85. package/engine/graphics/micron/format/serialization/MicronGeometryBinarySerializationAdapter.js +101 -0
  86. package/engine/graphics/micron/format/serialization/deserialize_attribute_spec.js +25 -0
  87. package/engine/graphics/micron/format/serialization/deserialize_patch.js +104 -0
  88. package/engine/graphics/micron/format/serialization/serialize_attribute_spec.js +18 -0
  89. package/engine/graphics/micron/format/serialization/serialize_patch.js +84 -0
  90. package/engine/graphics/micron/render/VirtualGeometryBuilder.js +24 -8
  91. package/engine/graphics/micron/render/culling/{PathCullingSystem.js → PatchCullingSystem.js} +1 -1
  92. package/engine/graphics/micron/render/instanced/AttributeDataTexture.js +1 -1
  93. package/engine/graphics/micron/render/refinement/ActivePatchList.js +6 -25
  94. package/engine/graphics/micron/render/refinement/RefinementSpec.js +98 -0
  95. package/engine/graphics/micron/render/v1/MaterialVertexSpec.js +21 -0
  96. package/engine/graphics/micron/render/v1/VGThreeRenderer.js +12 -9
  97. package/engine/graphics/micron/render/v1/getTransformedPositionsCached.js +1 -1
  98. package/engine/graphics/render/buffer/buffers/ColorAndDepthFrameBuffer.js +5 -3
  99. package/engine/graphics/render/forward_plus/data/TextureBackedMemoryRegion.js +1 -1
  100. package/engine/graphics/render/forward_plus/prototypeLightManager.js +1 -1
  101. package/engine/graphics/render/visibility/hiz/prototypeHiZ.js +11 -6
  102. package/engine/graphics/shadows/ShadowMapRenderer.js +12 -2
  103. package/engine/graphics/texture/cubemap/load_environment_map.js +29 -3
  104. package/engine/graphics/texture/sampler/Sampler2D.js +18 -62
  105. package/engine/graphics/texture/sampler/TextureBinaryBufferSerializer.js +1 -1
  106. package/engine/graphics/texture/sampler/debug/paintSamplerOnHTML.js +3 -2
  107. package/engine/graphics/texture/sampler/differenceSampler.js +31 -0
  108. package/engine/graphics/texture/sampler/typedArrayConstructorByInstance.js +25 -0
  109. package/engine/graphics/texture/sampler/util/drawSamplerHTML.js +3 -2
  110. package/engine/network/convertPathToURL.js +7 -1
  111. package/engine/plugin/EnginePluginManager.d.ts +9 -0
  112. package/engine/reference/v2/Reference.d.ts +7 -0
  113. package/package.json +1 -1
  114. package/view/minimap/gl/MinimapMarkersGL.js +2 -2
  115. package/engine/graphics/micron/build/clustering/cluster_mesh_vertices.js +0 -3
  116. package/engine/graphics/micron/render/RefinementSpec.js +0 -181
@@ -0,0 +1,96 @@
1
+ import { assert } from "../../../assert.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number[]|Float32Array} result
6
+ * @param {number[]|Float32Array|Float64Array} aabb_corners
7
+ * @param {number[]|Float32Array} projection_matrix
8
+ */
9
+ export function aabb3_matrix4_project_by_corners(result, aabb_corners, projection_matrix) {
10
+ assert.greaterThanOrEqual(result.length, 6, 'result.length must >= 6');
11
+ assert.greaterThanOrEqual(aabb_corners.length, 24, 'aabb_corners.length must >= 24');
12
+ assert.greaterThanOrEqual(projection_matrix.length, 16, 'projection_matrix.length must >= 16');
13
+
14
+ // read matrix into local variables for speed
15
+ const a0 = projection_matrix[0];
16
+ const a1 = projection_matrix[1];
17
+ const a2 = projection_matrix[2];
18
+ const a3 = projection_matrix[3];
19
+
20
+ const b0 = projection_matrix[4];
21
+ const b1 = projection_matrix[5];
22
+ const b2 = projection_matrix[6];
23
+ const b3 = projection_matrix[7];
24
+
25
+ const c0 = projection_matrix[8];
26
+ const c1 = projection_matrix[9];
27
+ const c2 = projection_matrix[10];
28
+ const c3 = projection_matrix[11];
29
+
30
+ const d0 = projection_matrix[12];
31
+ const d1 = projection_matrix[13];
32
+ const d2 = projection_matrix[14];
33
+ const d3 = projection_matrix[15];
34
+
35
+ // initialize bounds
36
+ let x0 = Number.POSITIVE_INFINITY;
37
+ let y0 = Number.POSITIVE_INFINITY;
38
+ let z0 = Number.POSITIVE_INFINITY;
39
+
40
+ let x1 = Number.NEGATIVE_INFINITY;
41
+ let y1 = Number.NEGATIVE_INFINITY;
42
+ let z1 = Number.NEGATIVE_INFINITY;
43
+
44
+
45
+ for (let i = 0; i < 24; i += 3) {
46
+
47
+ // read corner
48
+ const _x = aabb_corners[i];
49
+ const _y = aabb_corners[i + 1];
50
+ const _z = aabb_corners[i + 2];
51
+
52
+ // apply transform
53
+ const t_x = a0 * _x + b0 * _y + c0 * _z + d0;
54
+ const t_y = a1 * _x + b1 * _y + c1 * _z + d1;
55
+ const t_z = a2 * _x + b2 * _y + c2 * _z + d2;
56
+ const t_w = a3 * _x + b3 * _y + c3 * _z + d3;
57
+
58
+ // perspective divide and normalization (-1,1 space projected to -0.5,0.5)
59
+ const d = 1 / t_w;
60
+
61
+ // finally compute screen-space coordinates of the corner
62
+ const x = t_x * d;
63
+ const y = t_y * d;
64
+ const z = t_z * d;
65
+
66
+ if (x0 > x) {
67
+ x0 = x;
68
+ }
69
+ if (x1 < x) {
70
+ x1 = x;
71
+ }
72
+
73
+ if (y0 > y) {
74
+ y0 = y;
75
+ }
76
+ if (y1 < y) {
77
+ y1 = y;
78
+ }
79
+
80
+ if (z0 > z) {
81
+ z0 = z;
82
+ }
83
+ if (z1 < z) {
84
+ z1 = z;
85
+ }
86
+
87
+ }
88
+
89
+ result[0] = x0;
90
+ result[1] = y0;
91
+ result[2] = z0;
92
+
93
+ result[3] = x1;
94
+ result[4] = y1;
95
+ result[5] = z1;
96
+ }
@@ -1,9 +1,9 @@
1
1
  //
2
2
 
3
3
 
4
- import Vector3 from "../../../../../core/geom/Vector3.js";
5
- import Quaternion, { quat3_createFromAxisAngle } from "../../../../../core/geom/Quaternion.js";
6
- import { max2 } from "../../../../../core/math/max2.js";
4
+ import Vector3 from "../Vector3.js";
5
+ import Quaternion, { quat3_createFromAxisAngle } from "../Quaternion.js";
6
+ import { max2 } from "../../math/max2.js";
7
7
 
8
8
  const tangent = new Vector3();
9
9
 
@@ -1,5 +1,5 @@
1
1
  import { compute_bounding_cone_of_2_cones } from "./compute_bounding_cone_of_2_cones.js";
2
- import { ConicRay } from "../../../../../core/geom/ConicRay.js";
2
+ import { ConicRay } from "../ConicRay.js";
3
3
 
4
4
  /**
5
5
  *
@@ -2,9 +2,9 @@
2
2
 
3
3
 
4
4
  import { vec3 } from "gl-matrix";
5
- import { Miniball } from "../../../../../core/geom/packing/miniball/Miniball.js";
6
- import { PointSet } from "../../../../../core/geom/packing/miniball/PointSet.js";
7
- import { max2 } from "../../../../../core/math/max2.js";
5
+ import { Miniball } from "../packing/miniball/Miniball.js";
6
+ import { PointSet } from "../packing/miniball/PointSet.js";
7
+ import { max2 } from "../../math/max2.js";
8
8
 
9
9
  /**
10
10
  *
@@ -0,0 +1,25 @@
1
+ import { v3_length } from "../../Vector3.d.ts";
2
+
3
+ /**
4
+ * Normalize a plane in-place
5
+ * @param {number[]} source
6
+ * @param {number} source_offset
7
+ */
8
+ function array_normalize_plane(source, source_offset) {
9
+ const _x = source[source_offset];
10
+ const _y = source[source_offset + 1];
11
+ const _z = source[source_offset + 2];
12
+
13
+ const length = v3_length(_x, _y, _z);
14
+
15
+ const inverseNormalLength = 1.0 / length;
16
+
17
+ /*
18
+ By re-using values already in the registers instead of using *= we save a few extra READ ops
19
+ */
20
+ source[source_offset] = _x * inverseNormalLength;
21
+ source[source_offset + 1] = _y * inverseNormalLength;
22
+ source[source_offset + 2] = _z * inverseNormalLength;
23
+
24
+ source[source_offset + 3] *= inverseNormalLength;
25
+ }
@@ -0,0 +1,60 @@
1
+ import { v3_length } from "../../Vector3.js";
2
+
3
+ /**
4
+ *
5
+ * @param {number[]} destination
6
+ * @param {number} destination_offset
7
+ * @param {number} x
8
+ * @param {number} y
9
+ * @param {number} z
10
+ * @param {number} w
11
+ */
12
+ function array_set_plane_normalized(destination, destination_offset, x, y, z, w) {
13
+ const length = v3_length(x, y, z);
14
+
15
+ const inverseNormalLength = 1.0 / length;
16
+
17
+ destination[destination_offset] = x * inverseNormalLength;
18
+ destination[destination_offset + 1] = y * inverseNormalLength;
19
+ destination[destination_offset + 2] = z * inverseNormalLength;
20
+ destination[destination_offset + 3] = w * inverseNormalLength;
21
+ }
22
+
23
+ /**
24
+ * Set frustum from projection matrix
25
+ * @param {number[]|Float32Array} frustum_planes
26
+ * @param {number[]} me
27
+ */
28
+ export function array_setFromProjectionMatrix(frustum_planes, me) {
29
+
30
+ const me0 = me[0];
31
+ const me3 = me[3];
32
+
33
+ const me4 = me[4];
34
+ const me7 = me[7];
35
+
36
+ const me8 = me[8];
37
+ const me11 = me[11];
38
+
39
+ const me12 = me[12];
40
+ const me15 = me[15];
41
+
42
+ array_set_plane_normalized(frustum_planes, 0, me3 - me0, me7 - me4, me11 - me8, me15 - me12);
43
+ array_set_plane_normalized(frustum_planes, 4, me3 + me0, me7 + me4, me11 + me8, me15 + me12);
44
+
45
+ const me1 = me[1];
46
+ const me5 = me[5];
47
+ const me9 = me[9];
48
+ const me13 = me[13];
49
+
50
+ array_set_plane_normalized(frustum_planes, 8, me3 + me1, me7 + me5, me11 + me9, me15 + me13);
51
+ array_set_plane_normalized(frustum_planes, 12, me3 - me1, me7 - me5, me11 - me9, me15 - me13);
52
+
53
+ const me2 = me[2];
54
+ const me6 = me[6];
55
+ const me10 = me[10];
56
+ const me14 = me[14];
57
+
58
+ array_set_plane_normalized(frustum_planes, 16, me3 - me2, me7 - me6, me11 - me10, me15 - me14);
59
+ array_set_plane_normalized(frustum_planes, 20, me3 + me2, me7 + me6, me11 + me10, me15 + me14);
60
+ }
@@ -1,5 +1,5 @@
1
1
  import { decode_hemioct_to_unit, encode_unit_to_hemioct } from "./encode_unit3_hemioct.js";
2
- import { v3_length } from "../../../../core/geom/Vector3.js";
2
+ import { v3_length } from "../Vector3.d.ts";
3
3
 
4
4
  test('encode-decode', () => {
5
5
  const v0 = [];
@@ -1,5 +1,5 @@
1
- import { DataType2TypedArrayConstructorMapping } from "../../../../../core/collection/table/DataType2TypedArrayConstructorMapping.js";
2
- import { assert } from "../../../../../core/assert.js";
1
+ import { DataType2TypedArrayConstructorMapping } from "../collection/table/DataType2TypedArrayConstructorMapping.js";
2
+ import { assert } from "../assert.js";
3
3
 
4
4
  export class SquareMatrix {
5
5
  /**
@@ -1,5 +1,5 @@
1
1
  import { SquareMatrix } from "./SquareMatrix.js";
2
- import { DataType } from "../../../../../core/collection/table/DataType.js";
2
+ import { DataType } from "../collection/table/DataType.js";
3
3
 
4
4
  test('set/get cell', () => {
5
5
  const m = new SquareMatrix(2, DataType.Uint8);
@@ -1,4 +1,4 @@
1
- import { Edge } from "../../../../../core/graph/Edge.js";
1
+ import { Edge } from "./Edge.js";
2
2
 
3
3
  export class WeightedEdge extends Edge {
4
4
  constructor(a, b) {
@@ -1,6 +1,6 @@
1
- import { Graph } from "../../../../../core/graph/v2/Graph.js";
1
+ import { Graph } from "./v2/Graph.js";
2
2
  import { MultiNode } from "./MultiNode.js";
3
- import { compute_face_connection_weight } from "../clustering/compute_face_connection_weight.js";
3
+ import { compute_face_connection_weight } from "../../engine/graphics/micron/build/clustering/compute_face_connection_weight.js";
4
4
  import { WeightedEdge } from "./WeightedEdge.js";
5
5
  import { graph_compute_disconnected_clusters } from "./graph_compute_disconnected_clusters.js";
6
6
 
@@ -1,5 +1,5 @@
1
- import { Metis } from "../graph/metis/metis.js";
2
- import { metis_options } from "../graph/metis/metis_options.js";
1
+ import { Metis } from "./metis/metis.js";
2
+ import { metis_options } from "./metis/metis_options.js";
3
3
 
4
4
  /**
5
5
  * How many times to retry partitioning before giving up
@@ -7,10 +7,6 @@ import { metis_options } from "../graph/metis/metis_options.js";
7
7
  */
8
8
  const MAX_STEPS = 50;
9
9
 
10
- function cluster_mesh_metis_detailed(mesh, patch_size) {
11
-
12
- }
13
-
14
10
  /**
15
11
  *
16
12
  * @param {Uint32Array} result
@@ -1,4 +1,4 @@
1
- import FastBinaryHeap from "../../../../navigation/grid/FastBinaryHeap.js";
1
+ import FastBinaryHeap from "../../engine/navigation/grid/FastBinaryHeap.js";
2
2
  import { mn_graph_collapse_weighted_edge } from "./mn_graph_collapse_weighted_edge.js";
3
3
  import { WeightedEdge } from "./WeightedEdge.js";
4
4
 
@@ -1,4 +1,4 @@
1
- import { Graph } from "../../../../../core/graph/v2/Graph.js";
1
+ import { Graph } from "./v2/Graph.js";
2
2
  import { MultiNode } from "./MultiNode.js";
3
3
  import { WeightedEdge } from "./WeightedEdge.js";
4
4
  import { coarsen_graph } from "./coarsen_graph.js";
@@ -1,5 +1,5 @@
1
1
  import { SquareMatrix } from "../SquareMatrix.js";
2
- import { DataType } from "../../../../../../core/collection/table/DataType.js";
2
+ import { DataType } from "../../collection/table/DataType.js";
3
3
  import { matrix_eigenvalues_in_place } from "./eigen.js";
4
4
 
5
5
  function roughly_equal_array_vectors(actual, expected) {
@@ -1,10 +1,10 @@
1
1
  //
2
- import { seededRandom } from "../../../../../core/math/random/seededRandom.js";
3
- import { randomIntegerBetween } from "../../../../../core/math/MathUtils.js";
2
+ import { seededRandom } from "../math/random/seededRandom.js";
3
+ import { randomIntegerBetween } from "../math/MathUtils.js";
4
4
  import { SquareMatrix } from "./SquareMatrix.js";
5
- import { DataType } from "../../../../../core/collection/table/DataType.js";
6
- import { BitSet } from "../../../../../core/binary/BitSet.js";
7
- import FastBinaryHeap from "../../../../navigation/grid/FastBinaryHeap.js";
5
+ import { DataType } from "../collection/table/DataType.js";
6
+ import { BitSet } from "../binary/BitSet.js";
7
+ import FastBinaryHeap from "../../engine/navigation/grid/FastBinaryHeap.js";
8
8
 
9
9
  /**
10
10
  * @template N
@@ -1,6 +1,6 @@
1
1
  import { graph_degree_matrix } from "./graph_degree_matrix.js";
2
2
  import { SquareMatrix } from "./SquareMatrix.js";
3
- import { DataType } from "../../../../../core/collection/table/DataType.js";
3
+ import { DataType } from "../collection/table/DataType.js";
4
4
  import { graph_adjacency_matrix } from "./graph_adjacency_matrix.js";
5
5
 
6
6
  /**
@@ -1,5 +1,5 @@
1
- import WorkerBuilder from "../../../../../../core/process/worker/WorkerBuilder.js";
2
- import { OnDemandWorkerManager } from "../../../../../../core/process/worker/OnDemandWorkerManager.js";
1
+ import WorkerBuilder from "../../process/worker/WorkerBuilder.js";
2
+ import { OnDemandWorkerManager } from "../../process/worker/OnDemandWorkerManager.js";
3
3
 
4
4
 
5
5
  export class Metis {
@@ -17,6 +17,8 @@ export class ActionProcessor<CTX, MD> {
17
17
 
18
18
  redo(): void
19
19
 
20
+ navigateTo(mark: MD): boolean
21
+
20
22
  doMany(actions: Action<CTX>[]): void
21
23
 
22
24
  do(action: Action<CTX>): this
@@ -202,6 +202,64 @@ export class ActionProcessor {
202
202
 
203
203
  }
204
204
 
205
+ /**
206
+ * Navigate to a specific mark back or forward
207
+ * @param {M} mark_descriptor specific mark description
208
+ * @returns {boolean} true on success, false otherwise (e.g. mark not found)
209
+ * @throws {Error} when mark is non-unique
210
+ */
211
+ navigateTo(mark_descriptor) {
212
+ // find all matching marks
213
+ const matching_marks = this.marks.filter(m => m.description === mark_descriptor);
214
+
215
+ if (matching_marks.length === 0) {
216
+ // not found
217
+ return false;
218
+ }
219
+
220
+ if (matching_marks.length > 1) {
221
+ throw new Error(`Attempting to navigate to a non-unique mark descriptor '${mark_descriptor}'. Mark descriptor must be unique, instead ${matching_marks.length} matches were found`);
222
+ }
223
+
224
+ const match = matching_marks[0];
225
+
226
+ const target = match.index;
227
+
228
+ let temp_cursor = this.cursor;
229
+
230
+ if (target > this.cursor) {
231
+
232
+ while (target > this.cursor) {
233
+ // navigate forward
234
+ this.redo();
235
+
236
+ if (temp_cursor === this.cursor) {
237
+ // no cursor change
238
+ return false;
239
+ }
240
+
241
+ temp_cursor = this.cursor;
242
+ }
243
+
244
+ } else if (target < this.cursor) {
245
+
246
+ while (target < this.cursor) {
247
+ // navigate backwards
248
+ this.undo();
249
+
250
+ if (temp_cursor === this.cursor) {
251
+ // no cursor change
252
+ return false;
253
+ }
254
+
255
+ temp_cursor = this.cursor;
256
+ }
257
+
258
+ }
259
+
260
+ return true;
261
+ }
262
+
205
263
  undo() {
206
264
  let markAddress = 0;
207
265
  /**
@@ -226,7 +284,7 @@ export class ActionProcessor {
226
284
  markAddress = 0;
227
285
  }
228
286
 
229
- //keep rewinding until we hit mark
287
+ //keep rewinding until we hit a mark
230
288
  while (this.cursor > markAddress && this.cursor > 0) {
231
289
  this.cursor--;
232
290
  const action = this.history.get(this.cursor);
@@ -0,0 +1,59 @@
1
+ import { ActionProcessor } from "./ActionProcessor.js";
2
+ import { Action } from "./Action.js";
3
+
4
+ class DummyContext {
5
+ constructor() {
6
+ this.value = 0;
7
+ }
8
+ }
9
+
10
+ class DummyAction extends Action {
11
+ apply(context) {
12
+ // do nothing
13
+ context.value++;
14
+ }
15
+
16
+ revert(context) {
17
+ context.value--;
18
+ }
19
+ }
20
+
21
+ test('navigateTo backwards', () => {
22
+ const ctx = new DummyContext();
23
+ const ap = new ActionProcessor(ctx);
24
+
25
+ ap.mark('a');
26
+ ap.do(new DummyAction());
27
+ ap.mark('b');
28
+ ap.do(new DummyAction());
29
+
30
+ expect(ap.navigateTo('a')).toBe(true);
31
+
32
+ expect(ctx.value).toBe(0);
33
+ });
34
+
35
+ test('navigateTo forward', () => {
36
+ const ctx = new DummyContext();
37
+ const ap = new ActionProcessor(ctx);
38
+
39
+ ap.mark('a');
40
+ ap.do(new DummyAction());
41
+ ap.mark('b');
42
+ ap.do(new DummyAction());
43
+ ap.mark('c');
44
+
45
+ ap.undo();
46
+ ap.undo();
47
+ ap.undo();
48
+
49
+ expect(ap.navigateTo('c')).toBe(true);
50
+
51
+ expect(ctx.value).toBe(2);
52
+ });
53
+
54
+ test('navigateTo non-existent on empty', () => {
55
+ const ctx = new DummyContext();
56
+ const ap = new ActionProcessor(ctx);
57
+
58
+ expect(ap.navigateTo('a')).toBe(false);
59
+ });
@@ -8,13 +8,14 @@ export class Mark {
8
8
  * @constructor
9
9
  */
10
10
  constructor(index, description) {
11
- assert.typeOf(index, 'number', 'index');
11
+ assert.isNumber(index, 'index');
12
12
 
13
13
  /**
14
14
  *
15
15
  * @type {number}
16
16
  */
17
17
  this.index = index;
18
+
18
19
  /**
19
20
  *
20
21
  * @type {D}
@@ -8,6 +8,7 @@ import {AssetManager} from "./asset/AssetManager";
8
8
  import {EntityManager} from "./ecs/EntityManager";
9
9
  import View from "../view/View";
10
10
  import Ticker from "./simulation/Ticker";
11
+ import {EnginePluginManager} from "./plugin/EnginePluginManager";
11
12
 
12
13
  export interface IEngineInitializationOptions {
13
14
  entityManager?: EntityManager
@@ -25,6 +26,7 @@ export default class Engine {
25
26
  public readonly devices: { keyboard: KeyboardDevice, pointer: PointerDevice }
26
27
  public readonly assetManager: AssetManager
27
28
  public readonly ticker: Ticker
29
+ public readonly plugins: EnginePluginManager
28
30
 
29
31
  public start(): Promise<any>
30
32
 
@@ -203,10 +203,10 @@ export class EngineHarness {
203
203
  *
204
204
  * @param {Engine} engine
205
205
  * @param {Vector3} [focus]
206
- * @param heightMap
207
- * @param heightRange
208
- * @param pitch
209
- * @param yaw
206
+ * @param [heightMap]
207
+ * @param [heightRange]
208
+ * @param [pitch]
209
+ * @param [yaw]
210
210
  * @param {number} [distance]
211
211
  * @param {Vector2} [terrainSize]
212
212
  * @param {number} [terrainResolution]
@@ -0,0 +1,19 @@
1
+ /**
2
+ *
3
+ * @param {WebGL2RenderingContext} gl
4
+ * @param {Sampler2D} sampler
5
+ * @param {ImageBitmap} bitmap
6
+ */
7
+ export function bitmap2sampler_gl(gl, sampler, bitmap) {
8
+ gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
9
+ gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
10
+
11
+ const w = sampler.width;
12
+ const h = sampler.height;
13
+
14
+ if (sampler.itemSize !== 4) {
15
+ throw new Error(`Expected sampler.itemSize to be 4, instead was '${sampler.itemSize}'`);
16
+ }
17
+
18
+ gl.readPixels(0, 0, w, h, gl.RGBA, gl.UNSIGNED_BYTE, sampler.data);
19
+ }
@@ -1,6 +1,7 @@
1
1
  import { Sampler2D } from "../../../graphics/texture/sampler/Sampler2D.js";
2
2
  import { assert } from "../../../../core/assert.js";
3
3
  import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqualStrict.js";
4
+ import { bitmap2sampler_gl } from "./bitmap2sampler_gl.js";
4
5
 
5
6
  /**
6
7
  *
@@ -8,23 +9,6 @@ import { isArrayEqualStrict } from "../../../../core/collection/array/isArrayEqu
8
9
  */
9
10
  const sampler_cache = new WeakMap();
10
11
 
11
- /**
12
- *
13
- * @param {WebGL2RenderingContext} gl
14
- * @param {Sampler2D} sampler
15
- * @param {ImageBitmap} bitmap
16
- */
17
- function bitmap2sampler_gl(gl, sampler, bitmap) {
18
- gl.texImage2D(gl.TEXTURE_2D, 0, gl.RGBA, gl.RGBA, gl.UNSIGNED_BYTE, bitmap);
19
- gl.drawBuffers([gl.COLOR_ATTACHMENT0]);
20
-
21
- const data = new Uint8Array(sampler.width * sampler.height * 4);
22
-
23
- gl.readPixels(0, 0, sampler.width, sampler.height, gl.RGBA, gl.UNSIGNED_BYTE, data);
24
-
25
- sampler.data = data;
26
- }
27
-
28
12
  /**
29
13
  *
30
14
  * @param {ImageBitmap} bitmap
@@ -45,7 +29,7 @@ function obtainSampler(bitmap, ctx) {
45
29
  const width = bitmap.width;
46
30
  const height = bitmap.height;
47
31
 
48
- const sampler = new Sampler2D(null, 4, width, height);
32
+ const sampler = Sampler2D.uint8(4, width, height);
49
33
 
50
34
  bitmap2sampler_gl(ctx, sampler, bitmap);
51
35
 
@@ -75,15 +59,19 @@ function obtainCanvasCtx(width, height) {
75
59
 
76
60
  if (ctx_ref === null || (gl = ctx_ref.deref()) === undefined) {
77
61
  const canvas = document.createElement('canvas');
62
+
78
63
  gl = canvas.getContext("webgl2");
79
64
  gl.activeTexture(gl.TEXTURE0);
65
+
80
66
  const texture = gl.createTexture();
67
+
81
68
  gl.bindTexture(gl.TEXTURE_2D, texture);
69
+
82
70
  const framebuffer = gl.createFramebuffer();
71
+
83
72
  gl.bindFramebuffer(gl.FRAMEBUFFER, framebuffer);
84
73
  gl.framebufferTexture2D(gl.FRAMEBUFFER, gl.COLOR_ATTACHMENT0, gl.TEXTURE_2D, texture, 0);
85
74
 
86
-
87
75
  ctx_ref = new WeakRef(gl);
88
76
  }
89
77
 
@@ -1,9 +1,5 @@
1
1
  import { BinaryNode } from "../../../core/bvh2/BinaryNode.js";
2
- import {
3
- deserializeRowFirstTable,
4
- RowFirstTable,
5
- serializeRowFirstTable
6
- } from "../../../core/collection/table/RowFirstTable.js";
2
+ import { RowFirstTable } from "../../../core/collection/table/RowFirstTable.js";
7
3
  import { InstancedMeshGroup } from "../../graphics/geometry/instancing/InstancedMeshGroup.js";
8
4
  import Vector3 from "../../../core/geom/Vector3.js";
9
5
  import { LeafNode } from "../../../core/bvh2/LeafNode.js";
@@ -19,6 +15,8 @@ import { traverseBinaryNodeUsingVisitor } from "../../../core/bvh2/traversal/tra
19
15
  import { serializeBinaryNodeToBinaryBuffer } from "../../../core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js";
20
16
  import { deserializeBinaryNodeFromBinaryBuffer } from "../../../core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js";
21
17
  import { computeGeometryBoundingSphereMiniball } from "../../graphics/geometry/buffered/computeGeometryBoundingSphereMiniball.js";
18
+ import { serializeRowFirstTable } from "../../../core/collection/table/serializeRowFirstTable.js";
19
+ import { deserializeRowFirstTable } from "../../../core/collection/table/deserializeRowFirstTable.js";
22
20
 
23
21
  /**
24
22
  * @readonly