@woosh/meep-engine 2.47.3 → 2.47.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 (130) hide show
  1. package/build/bundle-worker-image-decoder.js +1 -0
  2. package/build/bundle-worker-terrain.js +1 -0
  3. package/build/meep.cjs +1044 -933
  4. package/build/meep.min.js +1 -1
  5. package/build/meep.module.js +1044 -933
  6. package/package.json +2 -2
  7. package/src/core/binary/BitSet.spec.js +3 -3
  8. package/src/core/bvh2/BinaryNode.js +12 -10
  9. package/src/core/bvh2/aabb3/AABB3.js +30 -31
  10. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +1 -1
  11. package/src/core/bvh2/binary/BinaryBVH.js +1 -1
  12. package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +1 -1
  13. package/src/core/bvh2/bvh3/ExplicitBinaryBoundingVolumeHierarchy.js +1 -1
  14. package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +2 -2
  15. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +1 -1
  16. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +1 -1
  17. package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +10 -8
  18. package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +14 -22
  19. package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +13 -15
  20. package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +14 -21
  21. package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +16 -24
  22. package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +23 -26
  23. package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +10 -11
  24. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +2 -2
  25. package/src/core/bvh2/transform/tryRotateSingleNode.js +2 -2
  26. package/src/core/bvh2/traversal/aabb3_detailed_volume_intersection_callback_based.js +1 -1
  27. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +1 -1
  28. package/src/core/collection/SCRATCH_UINT32_TRAVERSAL_STACK.js +13 -0
  29. package/src/core/color/Color.d.ts +2 -1
  30. package/src/core/color/Color.js +30 -5
  31. package/src/core/color/ColorUtils.js +7 -5
  32. package/src/core/color/parseHex.js +11 -3
  33. package/src/core/color/rgb2hex.js +1 -1
  34. package/src/core/geom/3d/SurfacePoint3.d.ts +7 -0
  35. package/src/core/geom/3d/SurfacePoint3.js +56 -1
  36. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_combine.js +2 -2
  37. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_contains_point.js +1 -1
  38. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_frustum_degree.js +2 -2
  39. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_combined_surface_area.js +2 -2
  40. package/src/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.js +1 -1
  41. package/src/core/geom/3d/aabb/aabb3_compute_distance_above_plane_max.spec.js +8 -0
  42. package/src/core/geom/3d/aabb/{computeAABB3PlaneSide.js → aabb3_compute_plane_side.js} +1 -1
  43. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_detailed_volume_intersection.js +7 -7
  44. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_from_v3_array.js +4 -4
  45. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_from_v3_array_transformed.js +2 -2
  46. package/src/core/{bvh2/aabb3/aabb3_intersect_aabb3.js → geom/3d/aabb/aabb3_intersects_aabb3.js} +2 -2
  47. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_frustum_array.js +2 -2
  48. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_frustum_degree.js +4 -4
  49. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_line_segment.js +1 -1
  50. package/src/core/geom/3d/aabb/aabb3_intersects_ray.js +87 -0
  51. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray.spec.js +1 -1
  52. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray_branchless.js +2 -2
  53. package/src/core/{bvh2/aabb3/aabb3_intersect_ray_slab.js → geom/3d/aabb/aabb3_intersects_ray_slab.js} +35 -17
  54. package/src/core/geom/3d/aabb/aabb3_matrix4_project_by_corners.js +5 -1
  55. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_nearest_point_on_surface.js +2 -2
  56. package/src/core/geom/3d/aabb/aabb3_raycast.js +103 -0
  57. package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_signed_distance_sqr_to_point.js +1 -1
  58. package/src/core/geom/3d/aabb/computeBoundingBoxFromVertexData.js +4 -12
  59. package/src/core/geom/3d/aabb/compute_aabb_from_points.js +8 -1
  60. package/src/core/geom/3d/shape/UnitCubeShape3D.js +1 -1
  61. package/src/core/geom/3d/triangle/computeTriangleRayIntersection.js +4 -7
  62. package/src/core/model/node-graph/DataType.d.ts +4 -0
  63. package/src/core/model/node-graph/node/NodeDescription.d.ts +11 -1
  64. package/src/core/model/node-graph/node/NodeRegistry.spec.js +47 -1
  65. package/src/core/model/node-graph/node/Port.d.ts +3 -0
  66. package/src/core/model/node-graph/node/Port.js +7 -3
  67. package/src/core/model/node-graph/node/Port.spec.js +44 -0
  68. package/src/core/model/node-graph/node/PortDirection.d.ts +5 -0
  69. package/src/engine/asset/Asset.js +1 -1
  70. package/src/engine/asset/AssetLoadState.js +10 -0
  71. package/src/engine/asset/AssetManager.js +164 -228
  72. package/src/engine/asset/PendingAsset.js +61 -0
  73. package/src/engine/asset/loaders/GLTFAssetLoader.js +1 -1
  74. package/src/engine/ecs/foliage/InstancedFoliage.js +1 -1
  75. package/src/engine/ecs/storage/BinaryBufferSerializer.js +13 -1
  76. package/src/engine/ecs/storage/binary/collection/BinaryCollectionSerializer.js +11 -4
  77. package/src/engine/ecs/storage/binary/object/BinaryObjectSerializationAdapter2.js +54 -0
  78. package/src/engine/ecs/systems/RenderSystem.js +1 -33
  79. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +2 -4
  80. package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +6 -1
  81. package/src/engine/graphics/GraphicsEngine.js +5 -1
  82. package/src/engine/graphics/ecs/decal/v2/Decal.js +44 -2
  83. package/src/engine/graphics/ecs/decal/v2/DecalSerializationAdapter.js +31 -0
  84. package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +16 -5
  85. package/src/engine/graphics/ecs/decal/v2/prototypeDecalSystem.js +88 -56
  86. package/src/engine/graphics/geometry/buffered/compute_buffer_geometry_byte_size.js +5 -1
  87. package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +2 -2
  88. package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +1 -1
  89. package/src/engine/graphics/geometry/instancing/InstancedMeshGroup.js +3 -2
  90. package/src/engine/graphics/geometry/skining/computeSkinnedMeshBoundingVolumes.js +3 -2
  91. package/src/engine/graphics/micron/format/MicronGeometry.js +1 -1
  92. package/src/engine/graphics/micron/format/validate_patch_bounds.js +1 -1
  93. package/src/engine/graphics/micron/render/refinement/ActivePatchList.js +1 -1
  94. package/src/engine/graphics/micron/render/refinement/get_geometry_patch_cut.js +16 -16
  95. package/src/engine/graphics/render/forward_plus/LightManager.js +3 -0
  96. package/src/engine/graphics/render/forward_plus/LightManager.spec.js +5 -5
  97. package/src/engine/graphics/render/forward_plus/materials/FP_SHADER_CHUNK_APPLY_DECALS.js +4 -0
  98. package/src/engine/graphics/render/forward_plus/model/Decal.js +10 -2
  99. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +2 -2
  100. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +18 -16
  101. package/src/engine/graphics/render/gizmo/GizmoShapeRenderingInterface.js +2 -0
  102. package/src/engine/graphics/render/visibility/IncrementalDeltaSet.js +26 -13
  103. package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +8 -2
  104. package/src/engine/graphics/sh3/path_tracer/PathTracer.js +3 -3
  105. package/src/engine/graphics/sh3/path_tracer/prototypePathTracer.js +18 -15
  106. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_max.js +1 -1
  107. package/src/engine/graphics/texture/sampler/sampler2d_channel_compute_min.js +1 -1
  108. package/src/engine/graphics/three/three_computeObjectBoundingBox.js +56 -0
  109. package/src/engine/input/devices/{InputDeviceButton.d.ts → InputDeviceSwitch.d.ts} +1 -1
  110. package/src/engine/input/devices/{InputDeviceButton.js → InputDeviceSwitch.js} +1 -1
  111. package/src/engine/input/devices/KeyboardDevice.d.ts +2 -2
  112. package/src/engine/input/devices/KeyboardDevice.js +58 -40
  113. package/src/engine/input/devices/PointerDevice.js +224 -179
  114. package/src/core/bvh2/aabb3/aabb3_intersects_ray.js +0 -97
  115. package/src/core/geom/3d/aabb/aabb3_computeDistanceAbovePlane_max.spec.js +0 -8
  116. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_frustum_array.js +0 -0
  117. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_ray.js +0 -0
  118. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_array_intersects_ray_array.js +0 -0
  119. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_box_surface_area_2.js +0 -0
  120. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_compute_half_surface_area.js +0 -0
  121. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_compute_surface_area.js +0 -0
  122. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_corner_edge_mapping.js +0 -0
  123. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_corner_edge_mapping.spec.js +0 -0
  124. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_corner_mapping.js +0 -0
  125. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_corner_mapping.spec.js +0 -0
  126. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_edge_plane_mapping.js +0 -0
  127. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_expand_array.js +0 -0
  128. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_intersects_ray_fast.js +0 -0
  129. /package/src/core/{bvh2/aabb3 → geom/3d/aabb}/aabb3_score_boxes_SAH.js +0 -0
  130. /package/src/core/{bvh2/aabb3/aabb_score_boxes_SAH_delta.js → geom/3d/aabb/aabb3_score_boxes_SAH_delta.js} +0 -0
package/package.json CHANGED
@@ -5,7 +5,7 @@
5
5
  "description": "Fully featured ECS game engine written in JavaScript",
6
6
  "type": "module",
7
7
  "author": "Alexander Goldring",
8
- "version": "2.47.3",
8
+ "version": "2.47.10",
9
9
  "main": "build/meep.module.js",
10
10
  "module": "build/meep.module.js",
11
11
  "exports": {
@@ -39,7 +39,7 @@
39
39
  "opentype.js": "1.3.3",
40
40
  "robust-predicates": "3.0.1",
41
41
  "simplex-noise": "2.4.0",
42
- "three": "^0.135.0"
42
+ "three": "0.135.0 - 0.136.0"
43
43
  },
44
44
  "devDependencies": {
45
45
  "@babel/core": "7.20.12",
@@ -33,18 +33,18 @@ test("set and get a bit", () => {
33
33
  expect(set.get(10000)).toBe(false);
34
34
  });
35
35
 
36
- test("resizing up and down works as intended", () => {
36
+ test.skip("resizing up and down works as intended", () => {
37
37
  const set = new BitSet();
38
38
 
39
39
  const c0 = set.capacity();
40
40
 
41
- set.set(c0 + 1, true);
41
+ set.setRange(c0, c0 + 1000);
42
42
 
43
43
  const c1 = set.capacity();
44
44
  expect(c1).toBeGreaterThan(c0);
45
45
 
46
46
  //clear the bit
47
- set.set(c0 + 1, false);
47
+ set.clearRange(c0, c0 + 1001);
48
48
 
49
49
  expect(set.capacity()).toBeLessThan(c1);
50
50
  });
@@ -13,9 +13,9 @@ import { Node } from "./Node.js";
13
13
  import { surfaceAreaHeuristic } from "./sah/surfaceAreaHeuristic.js";
14
14
  import { BVHVisitor } from "./traversal/BVHVisitor.js";
15
15
  import { traverseBinaryNodeUsingVisitor } from "./traversal/traverseBinaryNodeUsingVisitor.js";
16
- import { aabb3_intersect_aabb3 } from "./aabb3/aabb3_intersect_aabb3.js";
17
- import { aabb3_box_surface_area_2 } from "./aabb3/aabb3_box_surface_area_2.js";
18
- import { aabb3_combined_surface_area } from "./aabb3/aabb3_combined_surface_area.js";
16
+ import { aabb3_intersects_aabb3 } from "../geom/3d/aabb/aabb3_intersects_aabb3.js";
17
+ import { aabb3_box_surface_area_2 } from "../geom/3d/aabb/aabb3_box_surface_area_2.js";
18
+ import { aabb3_combined_surface_area } from "../geom/3d/aabb/aabb3_combined_surface_area.js";
19
19
 
20
20
 
21
21
  /**
@@ -394,13 +394,15 @@ export class BinaryNode extends Node {
394
394
  const a = this.left;
395
395
  const b = this.right;
396
396
 
397
- this.x0 = min2(a.x0, b.x0);
398
- this.y0 = min2(a.y0, b.y0);
399
- this.z0 = min2(a.z0, b.z0);
397
+ const x0 = min2(a.x0, b.x0);
398
+ const y0 = min2(a.y0, b.y0);
399
+ const z0 = min2(a.z0, b.z0);
400
400
 
401
- this.x1 = max2(a.x1, b.x1);
402
- this.y1 = max2(a.y1, b.y1);
403
- this.z1 = max2(a.z1, b.z1);
401
+ const x1 = max2(a.x1, b.x1);
402
+ const y1 = max2(a.y1, b.y1);
403
+ const z1 = max2(a.z1, b.z1);
404
+
405
+ this.setBounds(x0, y0, z0, x1, y1, z1);
404
406
  }
405
407
 
406
408
  bubbleRefit() {
@@ -723,7 +725,7 @@ export class BinaryNode extends Node {
723
725
  stackPointer--;
724
726
  const node = stack[stackPointer];
725
727
 
726
- if (!aabb3_intersect_aabb3(
728
+ if (!aabb3_intersects_aabb3(
727
729
  x0, y0, z0, x1, y1, z1,
728
730
  node.x0, node.y0, node.z0, node.x1, node.y1, node.z1
729
731
  )) {
@@ -3,18 +3,19 @@
3
3
  */
4
4
 
5
5
 
6
- import { aabb3_computeDistanceAbovePlane_max } from "../../geom/3d/aabb/aabb3_compute_distance_above_plane_max.js";
7
- import { computeAABB3PlaneSide } from "../../geom/3d/aabb/computeAABB3PlaneSide.js";
6
+ import { aabb3_compute_distance_above_plane_max } from "../../geom/3d/aabb/aabb3_compute_distance_above_plane_max.js";
7
+ import { aabb3_compute_plane_side } from "../../geom/3d/aabb/aabb3_compute_plane_side.js";
8
8
  import computeMortonCode from "../../geom/3d/morton/Morton.js";
9
9
  import { aabb3_build_corners } from "../../geom/3d/aabb/aabb3_build_corners.js";
10
10
  import { assert } from "../../assert.js";
11
- import { aabb3_intersects_frustum_degree } from "./aabb3_intersects_frustum_degree.js";
12
- import { aabb3_intersects_line_segment } from "./aabb3_intersects_line_segment.js";
13
- import { aabb3_intersects_ray } from "./aabb3_intersects_ray.js";
14
- import { aabb3_compute_surface_area } from "./aabb3_compute_surface_area.js";
15
- import { aabb3_intersects_frustum_array } from "./aabb3_intersects_frustum_array.js";
11
+ import { aabb3_intersects_frustum_degree } from "../../geom/3d/aabb/aabb3_intersects_frustum_degree.js";
12
+ import { aabb3_intersects_line_segment } from "../../geom/3d/aabb/aabb3_intersects_line_segment.js";
13
+ import { aabb3_intersects_ray } from "../../geom/3d/aabb/aabb3_intersects_ray.js";
14
+ import { aabb3_compute_surface_area } from "../../geom/3d/aabb/aabb3_compute_surface_area.js";
15
+ import { aabb3_intersects_frustum_array } from "../../geom/3d/aabb/aabb3_intersects_frustum_array.js";
16
16
  import { aabb3_matrix4_project } from "../../geom/3d/aabb/aabb3_matrix4_project.js";
17
- import { aabb3_signed_distance_sqr_to_point } from "./aabb3_signed_distance_sqr_to_point.js";
17
+ import { aabb3_signed_distance_sqr_to_point } from "../../geom/3d/aabb/aabb3_signed_distance_sqr_to_point.js";
18
+ import { aabb3_array_contains_point } from "../../geom/3d/aabb/aabb3_array_contains_point.js";
18
19
 
19
20
 
20
21
  export class AABB3 {
@@ -103,19 +104,14 @@ export class AABB3 {
103
104
  }
104
105
 
105
106
  /**
106
- *
107
+ * @deprecated use {@link aabb3_array_contains_point} directly
107
108
  * @param {number} x
108
109
  * @param {number} y
109
110
  * @param {number} z
110
111
  * @returns {boolean}
111
112
  */
112
113
  containsPoint(x, y, z) {
113
- return x >= this.x0
114
- && x <= this.x1
115
- && y >= this.y0
116
- && y <= this.y1
117
- && z >= this.z0
118
- && z <= this.z1;
114
+ return aabb3_array_contains_point(this, x, y, z);
119
115
  }
120
116
 
121
117
  /**
@@ -127,15 +123,9 @@ export class AABB3 {
127
123
  * @returns {boolean}
128
124
  */
129
125
  containsPointWithTolerance(x, y, z, tolerance) {
130
- if (
131
- (x + tolerance) < this.x0 || (x - tolerance) > this.x1
126
+ return !((x + tolerance) < this.x0 || (x - tolerance) > this.x1
132
127
  || (y + tolerance) < this.y0 || (y - tolerance) > this.y1
133
- || (z + tolerance) < this.z0 || (z - tolerance) > this.z1
134
- ) {
135
- return false;
136
- }
137
-
138
- return true;
128
+ || (z + tolerance) < this.z0 || (z - tolerance) > this.z1);
139
129
  }
140
130
 
141
131
  computeMortonCode() {
@@ -187,6 +177,13 @@ export class AABB3 {
187
177
  * @param {Number} z1
188
178
  */
189
179
  setBounds(x0, y0, z0, x1, y1, z1) {
180
+ assert.notNaN(x0, 'x0');
181
+ assert.notNaN(y0, 'y0');
182
+ assert.notNaN(z0, 'z0');
183
+ assert.notNaN(x1, 'x1');
184
+ assert.notNaN(y1, 'y1');
185
+ assert.notNaN(z1, 'z1');
186
+
190
187
  /**
191
188
  *
192
189
  * @type {number}
@@ -713,13 +710,15 @@ export class AABB3 {
713
710
  readFromArray(source, offset = 0) {
714
711
  assert.isNonNegativeInteger(offset, 'offset');
715
712
 
716
- this.x0 = source[offset];
717
- this.y0 = source[offset + 1];
718
- this.z0 = source[offset + 2];
713
+ const _x0 = source[offset];
714
+ const _y0 = source[offset + 1];
715
+ const _z0 = source[offset + 2];
716
+
717
+ const _x1 = source[offset + 3];
718
+ const _y1 = source[offset + 4];
719
+ const _z1 = source[offset + 5];
719
720
 
720
- this.x1 = source[offset + 3];
721
- this.y1 = source[offset + 4];
722
- this.z1 = source[offset + 5];
721
+ this.setBounds(_x0, _y0, _z0, _x1, _y1, _z1);
723
722
  }
724
723
 
725
724
  /**
@@ -729,7 +728,7 @@ export class AABB3 {
729
728
  computePlaneSide(plane) {
730
729
  const normal = plane.normal;
731
730
 
732
- return computeAABB3PlaneSide(
731
+ return aabb3_compute_plane_side(
733
732
  normal.x, normal.y, normal.z, plane.constant,
734
733
  this.x0, this.y0, this.z0,
735
734
  this.x1, this.y1, this.z1
@@ -745,7 +744,7 @@ export class AABB3 {
745
744
  * @returns {number}
746
745
  */
747
746
  computeDistanceAbovePlane(normal_x, normal_y, normal_z, offset) {
748
- return aabb3_computeDistanceAbovePlane_max(
747
+ return aabb3_compute_distance_above_plane_max(
749
748
  normal_x, normal_y, normal_z, offset,
750
749
  this.x0, this.y0, this.z0,
751
750
  this.x1, this.y1, this.z1
@@ -6,7 +6,7 @@ import { array_swap } from "../../../collection/array/array_swap.js";
6
6
  import { mortonEncode_magicbits } from "../../../geom/3d/morton/mortonEncode_magicbits.js";
7
7
  import { min3 } from "../../../math/min3.js";
8
8
  import { max3 } from "../../../math/max3.js";
9
- import { aabb3_compute_half_surface_area } from "../../aabb3/aabb3_compute_half_surface_area.js";
9
+ import { aabb3_compute_half_surface_area } from "../../../geom/3d/aabb/aabb3_compute_half_surface_area.js";
10
10
 
11
11
  /**
12
12
  * @readonly
@@ -3,7 +3,7 @@
3
3
  */
4
4
  import PrimitiveType from "../../binary/type/PrimitiveTypes.js";
5
5
  import BinaryStructure from "../../binary/type/Type.js";
6
- import { aabb3_intersects_ray } from "../aabb3/aabb3_intersects_ray.js";
6
+ import { aabb3_intersects_ray } from "../../geom/3d/aabb/aabb3_intersects_ray.js";
7
7
 
8
8
  const NodeType = {
9
9
  LEAF: 0,
@@ -1,7 +1,7 @@
1
1
  import { noop } from "../../function/Functions.js";
2
2
  import { IndexedBinaryBVHVisitor } from "./IndexedBinaryBVHVisitor.js";
3
3
  import { NodeType } from "./NodeType.js";
4
- import { aabb3_intersects_ray } from "../aabb3/aabb3_intersects_ray.js";
4
+ import { aabb3_intersects_ray } from "../../geom/3d/aabb/aabb3_intersects_ray.js";
5
5
 
6
6
  export class RayLeafIntersectionVisitor extends IndexedBinaryBVHVisitor {
7
7
  constructor() {
@@ -1,4 +1,4 @@
1
- import { aabb3_compute_surface_area } from "../aabb3/aabb3_compute_surface_area.js";
1
+ import { aabb3_compute_surface_area } from "../../geom/3d/aabb/aabb3_compute_surface_area.js";
2
2
  import { min2 } from "../../math/min2.js";
3
3
  import { max2 } from "../../math/max2.js";
4
4
  import { assert } from "../../assert.js";
@@ -1,5 +1,5 @@
1
1
  import { AABB3 } from "../aabb3/AABB3.js";
2
- import { aabb3_from_v3_array } from "../aabb3/aabb3_from_v3_array.js";
2
+ import { aabb3_from_v3_array } from "../../geom/3d/aabb/aabb3_from_v3_array.js";
3
3
  import morton from "../../geom/3d/morton/Morton.js";
4
4
  import { arrayQuickSort } from "../../collection/array/arrayQuickSort.js";
5
5
  import { compute_triangle_group_aabb3 } from "../../../engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.js";
@@ -133,7 +133,7 @@ export function ebvh_build_for_geometry_morton(bvh, index_array, position_array)
133
133
  let unprocessed_node_count = tri_count;
134
134
 
135
135
 
136
- while (used_index < node_total_count) {
136
+ while (used_index < node_total_count && unprocessed_node_count > 1) {
137
137
 
138
138
  let added_nodes = 0;
139
139
  let cursor = 0;
@@ -1,5 +1,5 @@
1
1
  import { BVHQuery } from "./BVHQuery.js";
2
- import { aabb3_array_intersects_frustum_array } from "../../aabb3/aabb3_array_intersects_frustum_array.js";
2
+ import { aabb3_array_intersects_frustum_array } from "../../../geom/3d/aabb/aabb3_array_intersects_frustum_array.js";
3
3
 
4
4
  const scratch_aabb = [];
5
5
 
@@ -1,5 +1,5 @@
1
1
  import { BVHQuery } from "./BVHQuery.js";
2
- import { aabb3_array_intersects_ray_array } from "../../aabb3/aabb3_array_intersects_ray_array.js";
2
+ import { aabb3_array_intersects_ray_array } from "../../../geom/3d/aabb/aabb3_array_intersects_ray_array.js";
3
3
 
4
4
  const scratch_aabb = [];
5
5
 
@@ -1,8 +1,10 @@
1
1
  //
2
2
 
3
3
  import { NULL_NODE } from "../ExplicitBinaryBoundingVolumeHierarchy.js";
4
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
5
+
6
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
4
7
 
5
- const traversal_stack = [];
6
8
  /**
7
9
  *
8
10
  * @param {number[]} destination
@@ -20,20 +22,20 @@ export function bvh_collect_user_data(destination, destination_offset, bvh, node
20
22
  *
21
23
  * @type {number}
22
24
  */
23
- let traversal_cursor = 0;
25
+ const stack_top = stack.pointer++;
24
26
 
25
- traversal_stack[traversal_cursor++] = node;
27
+ stack[stack_top] = node;
26
28
 
27
29
  let result_cursor = destination_offset;
28
30
 
29
- while (traversal_cursor > 0) {
30
- traversal_cursor--;
31
+ while (stack.pointer > stack_top) {
32
+ stack.pointer--;
31
33
 
32
34
  /**
33
35
  *
34
36
  * @type {number}
35
37
  */
36
- const node = traversal_stack[traversal_cursor];
38
+ const node = stack[stack.pointer];
37
39
 
38
40
  const node_is_leaf = bvh.node_is_leaf(node);
39
41
 
@@ -44,8 +46,8 @@ export function bvh_collect_user_data(destination, destination_offset, bvh, node
44
46
  const child2 = bvh.node_get_child2(node);
45
47
 
46
48
  // write to stack in reverse order, so that fist child ends up being visited first
47
- traversal_stack[traversal_cursor++] = child1;
48
- traversal_stack[traversal_cursor++] = child2;
49
+ stack[stack.pointer++] = child1;
50
+ stack[stack.pointer++] = child2;
49
51
 
50
52
  } else {
51
53
  // leaf node
@@ -1,17 +1,7 @@
1
1
  import { NULL_NODE } from "../ExplicitBinaryBoundingVolumeHierarchy.js";
2
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
2
3
 
3
- /**
4
- *
5
- * @type {number[]}
6
- */
7
- const traversal_stack = [];
8
-
9
- /**
10
- *
11
- * @type {number}
12
- */
13
- let traversal_cursor = 0;
14
-
4
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
15
5
 
16
6
  /**
17
7
  *
@@ -25,7 +15,6 @@ export function bvh_query_leaves_generic(
25
15
  result, result_offset,
26
16
  bvh, query
27
17
  ) {
28
- const stack_frame_address = traversal_cursor;
29
18
 
30
19
  const root = bvh.root;
31
20
 
@@ -33,18 +22,24 @@ export function bvh_query_leaves_generic(
33
22
  return 0;
34
23
  }
35
24
 
36
- traversal_stack[traversal_cursor++] = root;
25
+ /**
26
+ *
27
+ * @type {number}
28
+ */
29
+ const stack_top = stack.pointer++;
30
+
31
+ stack[stack_top] = root;
37
32
 
38
33
  let result_cursor = result_offset;
39
34
 
40
- while (traversal_cursor > stack_frame_address) {
41
- traversal_cursor--;
35
+ while (stack.pointer > stack_top) {
36
+ stack.pointer--;
42
37
 
43
38
  /**
44
39
  *
45
40
  * @type {number}
46
41
  */
47
- const node = traversal_stack[traversal_cursor];
42
+ const node = stack[stack.pointer];
48
43
 
49
44
  // test node against the ray
50
45
  const pass = query.evaluate(node, bvh);
@@ -62,8 +57,8 @@ export function bvh_query_leaves_generic(
62
57
  const child2 = bvh.node_get_child2(node);
63
58
 
64
59
  // write to stack in reverse order, so that fist child ends up being visited first
65
- traversal_stack[traversal_cursor++] = child2;
66
- traversal_stack[traversal_cursor++] = child1;
60
+ stack[stack.pointer++] = child2;
61
+ stack[stack.pointer++] = child1;
67
62
 
68
63
  } else {
69
64
  // leaf node
@@ -72,8 +67,5 @@ export function bvh_query_leaves_generic(
72
67
  }
73
68
  }
74
69
 
75
- // drop stack frame
76
- traversal_cursor = stack_frame_address;
77
-
78
70
  return result_cursor - result_offset;
79
71
  }
@@ -1,16 +1,13 @@
1
- import { aabb3_intersects_ray } from "../../aabb3/aabb3_intersects_ray.js";
1
+ import { aabb3_intersects_ray } from "../../../geom/3d/aabb/aabb3_intersects_ray.js";
2
2
  import {
3
3
  COLUMN_CHILD_1,
4
4
  COLUMN_CHILD_2,
5
5
  ELEMENT_WORD_COUNT,
6
6
  NULL_NODE
7
7
  } from "../ExplicitBinaryBoundingVolumeHierarchy.js";
8
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
8
9
 
9
- /**
10
- *
11
- * @type {number[]}
12
- */
13
- const traversal_stack = new Uint32Array(2048);
10
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
14
11
 
15
12
 
16
13
  /**
@@ -39,14 +36,15 @@ export function bvh_query_leaves_ray(
39
36
  }
40
37
 
41
38
 
42
- traversal_stack[0] = root;
43
-
44
- let result_cursor = result_offset;
45
39
  /**
46
40
  *
47
41
  * @type {number}
48
42
  */
49
- let traversal_cursor = 1;
43
+ const stack_top = stack.pointer++;
44
+
45
+ stack[stack_top] = root;
46
+
47
+ let result_cursor = result_offset;
50
48
 
51
49
  /*
52
50
  For performance, we bind data directly to avoid extra copies required to read out AABB
@@ -55,13 +53,13 @@ export function bvh_query_leaves_ray(
55
53
  const uint32 = bvh.__data_uint32;
56
54
 
57
55
  do {
58
- traversal_cursor--;
56
+ stack.pointer--;
59
57
 
60
58
  /**
61
59
  *
62
60
  * @type {number}
63
61
  */
64
- const node = traversal_stack[traversal_cursor];
62
+ const node = stack[stack.pointer];
65
63
 
66
64
  const address = node * ELEMENT_WORD_COUNT;
67
65
 
@@ -83,15 +81,15 @@ export function bvh_query_leaves_ray(
83
81
  if (child_1 !== NULL_NODE) {
84
82
 
85
83
  // this is not a leaf node, push children onto traversal stack
86
- traversal_stack[traversal_cursor++] = child_1;
87
- traversal_stack[traversal_cursor++] = uint32[address + COLUMN_CHILD_2];
84
+ stack[stack.pointer++] = child_1;
85
+ stack[stack.pointer++] = uint32[address + COLUMN_CHILD_2];
88
86
 
89
87
  } else {
90
88
  // leaf node
91
89
 
92
90
  result[result_cursor++] = node;
93
91
  }
94
- } while (traversal_cursor > 0);
92
+ } while (stack.pointer > stack_top);
95
93
 
96
94
  return result_cursor - result_offset;
97
95
  }
@@ -1,16 +1,7 @@
1
1
  import { NULL_NODE } from "../ExplicitBinaryBoundingVolumeHierarchy.js";
2
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
2
3
 
3
- /**
4
- *
5
- * @type {number[]}
6
- */
7
- const traversal_stack = [];
8
-
9
- /**
10
- *
11
- * @type {number}
12
- */
13
- let traversal_cursor = 0;
4
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
14
5
 
15
6
 
16
7
  /**
@@ -25,7 +16,6 @@ export function bvh_query_user_data_generic(
25
16
  result, result_offset,
26
17
  bvh, query
27
18
  ) {
28
- const stack_frame_address = traversal_cursor;
29
19
 
30
20
  const root = bvh.root;
31
21
 
@@ -33,18 +23,24 @@ export function bvh_query_user_data_generic(
33
23
  return 0;
34
24
  }
35
25
 
36
- traversal_stack[traversal_cursor++] = root;
26
+ /**
27
+ *
28
+ * @type {number}
29
+ */
30
+ const stack_top = stack.pointer++;
31
+
32
+ stack[stack_top] = root;
37
33
 
38
34
  let result_cursor = result_offset;
39
35
 
40
- while (traversal_cursor > stack_frame_address) {
41
- traversal_cursor--;
36
+ while (stack.pointer > stack_top) {
37
+ stack.pointer--;
42
38
 
43
39
  /**
44
40
  *
45
41
  * @type {number}
46
42
  */
47
- const node = traversal_stack[traversal_cursor];
43
+ const node = stack[stack.pointer];
48
44
 
49
45
  // test node against the query
50
46
  const pass = query.evaluate(node, bvh);
@@ -62,8 +58,8 @@ export function bvh_query_user_data_generic(
62
58
  const child2 = bvh.node_get_child2(node);
63
59
 
64
60
  // write to stack in reverse order, so that fist child ends up being visited first
65
- traversal_stack[traversal_cursor++] = child1;
66
- traversal_stack[traversal_cursor++] = child2;
61
+ stack[stack.pointer++] = child1;
62
+ stack[stack.pointer++] = child2;
67
63
 
68
64
  } else {
69
65
  // leaf node
@@ -72,8 +68,5 @@ export function bvh_query_user_data_generic(
72
68
  }
73
69
  }
74
70
 
75
- // drop stack frame
76
- traversal_cursor = stack_frame_address;
77
-
78
71
  return result_cursor - result_offset;
79
72
  }
@@ -1,12 +1,7 @@
1
1
  import { NULL_NODE } from "../ExplicitBinaryBoundingVolumeHierarchy.js";
2
- import { aabb3_signed_distance_sqr_to_point } from "../../aabb3/aabb3_signed_distance_sqr_to_point.js";
2
+ import { aabb3_signed_distance_sqr_to_point } from "../../../geom/3d/aabb/aabb3_signed_distance_sqr_to_point.js";
3
3
  import { max2 } from "../../../math/max2.js";
4
-
5
- /**
6
- *
7
- * @type {number[]}
8
- */
9
- const traversal_stack = [];
4
+ import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
10
5
 
11
6
  /**
12
7
  *
@@ -14,11 +9,7 @@ const traversal_stack = [];
14
9
  */
15
10
  const scratch_aabb = [];
16
11
 
17
- /**
18
- *
19
- * @type {number}
20
- */
21
- let traversal_cursor = 0;
12
+ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
22
13
 
23
14
  /**
24
15
  *
@@ -30,27 +21,31 @@ let traversal_cursor = 0;
30
21
  * @returns {number} user data of the leaf, or -1 if not found
31
22
  */
32
23
  export function bvh_query_user_data_nearest_to_point(bvh, x, y, z, max_distance = Infinity) {
33
- const stack_frame_address = traversal_cursor;
34
-
35
- const root = bvh.root;
24
+ const root = bvh.root;
36
25
 
37
26
  if (root === NULL_NODE) {
38
27
  return -1;
39
28
  }
40
29
 
41
- traversal_stack[traversal_cursor++] = root;
30
+ /**
31
+ *
32
+ * @type {number}
33
+ */
34
+ const stack_top = stack.pointer++;
35
+
36
+ stack[stack_top] = root;
42
37
 
43
38
  let best_leaf_data = -1;
44
39
  let best_distance_sqr = max_distance * max_distance;
45
40
 
46
- while (traversal_cursor > stack_frame_address) {
47
- traversal_cursor--;
41
+ while (stack.pointer > stack_top) {
42
+ stack.pointer--;
48
43
 
49
44
  /**
50
45
  *
51
46
  * @type {number}
52
47
  */
53
- const node = traversal_stack[traversal_cursor];
48
+ const node = stack[stack.pointer];
54
49
 
55
50
  bvh.node_get_aabb(node, scratch_aabb);
56
51
 
@@ -75,8 +70,8 @@ export function bvh_query_user_data_nearest_to_point(bvh, x, y, z, max_distance
75
70
  const child2 = bvh.node_get_child2(node);
76
71
 
77
72
  // write to stack in reverse order, so that fist child ends up being visited first
78
- traversal_stack[traversal_cursor++] = child1;
79
- traversal_stack[traversal_cursor++] = child2;
73
+ stack[stack.pointer++] = child1;
74
+ stack[stack.pointer++] = child2;
80
75
 
81
76
  } else {
82
77
 
@@ -89,8 +84,5 @@ export function bvh_query_user_data_nearest_to_point(bvh, x, y, z, max_distance
89
84
  }
90
85
  }
91
86
 
92
- // drop stack frame
93
- traversal_cursor = stack_frame_address;
94
-
95
87
  return best_leaf_data;
96
88
  }