@woosh/meep-engine 2.64.0 → 2.66.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +33388 -34714
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +33388 -34714
- package/editor/ecs/component/editors/ecs/terrain/TerrainEditor.js +4 -10
- package/editor/process/symbolic/makeGridPositionSymbolDisplay.js +7 -7
- package/editor/tools/SelectionTool.js +6 -95
- package/package.json +1 -1
- package/src/core/bvh2/BinaryNode.js +14 -14
- package/src/core/bvh2/LeafNode.js +4 -4
- package/src/core/bvh2/binary/2/BinaryUint32BVH.js +118 -113
- package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +54 -0
- package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +98 -0
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.d.ts → BVH.d.ts} +1 -1
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.js → BVH.js} +2 -2
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.spec.js → BVH.spec.js} +20 -20
- package/src/core/bvh2/bvh3/BvhClient.d.ts +11 -0
- package/src/core/bvh2/bvh3/{EBBVHLeafProxy.js → BvhClient.js} +22 -3
- package/src/core/bvh2/bvh3/BvhClient.spec.js +51 -0
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_incremental.js +2 -2
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.js +4 -4
- package/src/core/bvh2/bvh3/ebvh_build_for_geometry_morton.spec.js +3 -3
- package/src/core/bvh2/bvh3/ebvh_sort_for_traversal_depth_first.js +2 -8
- package/src/core/bvh2/bvh3/query/BVHQuery.js +1 -1
- package/src/core/bvh2/bvh3/query/bvh_collect_user_data.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_generic.spec.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.js +3 -8
- package/src/core/bvh2/bvh3/query/bvh_query_leaves_ray.spec.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.spec.js +2 -2
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.js +3 -3
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_nearest_to_point.spec.js +3 -3
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_frustum.js +3 -3
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.js +4 -4
- package/src/core/bvh2/bvh3/query/compute_tight_near_far_clipping_planes.spec.js +3 -3
- package/src/core/collection/array/array_copy.js +6 -0
- package/src/core/geom/3d/aabb/aabb3_array_combine.js +17 -8
- package/src/core/geom/3d/aabb/aabb3_array_intersects_ray.js +5 -2
- package/src/core/geom/3d/aabb/aabb3_array_set.js +25 -0
- package/src/core/geom/3d/aabb/aabb3_compute_half_surface_area.js +3 -0
- package/src/core/geom/3d/triangle/computeTriangleRayIntersectionBarycentric.js +8 -1
- package/src/engine/EngineHarness.js +23 -25
- package/src/engine/ecs/renderable/RenderSystem.js +44 -32
- package/src/engine/ecs/renderable/Renderable.d.ts +2 -2
- package/src/engine/ecs/renderable/Renderable.js +12 -11
- package/src/engine/ecs/terrain/ecs/Terrain.js +83 -87
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +106 -57
- package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +5 -2
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +122 -67
- package/src/engine/ecs/terrain/tiles/TerrainTileManager.js +162 -146
- package/src/engine/ecs/terrain/tiles/TileBuildWorker.js +16 -5
- package/src/engine/graphics/camera/testClippingPlaneComputation.js +3 -6
- package/src/engine/graphics/debug/VisualSymbolLine.js +1 -0
- package/src/engine/graphics/ecs/camera/CameraSystem.js +9 -9
- package/src/engine/graphics/ecs/camera/auto_set_camera_clipping_planes.js +3 -23
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +22 -24
- package/src/engine/graphics/ecs/light/LightSystem.js +12 -48
- package/src/engine/graphics/ecs/mesh/Mesh.js +8 -8
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +12 -36
- package/src/engine/graphics/ecs/mesh/updateNodeByTransformAndBBB.js +3 -43
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +6 -6
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.d.ts +3 -3
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometrySystem.js +16 -18
- package/src/engine/graphics/ecs/mesh-v2/render/ShadedGeometryRendererContext.js +5 -5
- package/src/engine/graphics/ecs/trail2d/Trail2D.js +105 -106
- package/src/engine/graphics/ecs/trail2d/Trail2DSystem.js +60 -61
- package/src/engine/graphics/ecs/trail2d/makeGradientTrail.js +3 -3
- package/src/engine/graphics/ecs/water/WATER_SIZE.js +1 -0
- package/src/engine/graphics/ecs/water/Water.js +84 -42
- package/src/engine/graphics/ecs/water/WaterSystem.js +53 -105
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +13 -7
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +58 -0
- package/src/engine/graphics/particles/ecs/ParticleEmitterSystem.js +32 -62
- package/src/engine/graphics/particles/particular/engine/ParticularEngine.js +9 -11
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +4 -4
- package/src/engine/graphics/particles/particular/engine/renderers/billboard/prototypeBillboardRenderer.js +8 -11
- package/src/engine/graphics/render/forward_plus/LightManager.js +30 -32
- package/src/engine/graphics/render/forward_plus/LightRenderMetadata.js +3 -3
- package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +21 -19
- package/src/engine/graphics/render/layers/RenderLayer.d.ts +8 -2
- package/src/engine/graphics/render/layers/RenderLayer.js +7 -65
- package/src/engine/graphics/render/make_bvh_visibility_builder.js +64 -0
- package/src/engine/graphics/sh3/LightProbeVolume.js +19 -19
- package/src/engine/graphics/sh3/path_tracer/GeometryBVHBatched.js +4 -6
- package/src/engine/graphics/sh3/path_tracer/PathTracer.js +17 -19
- package/src/engine/graphics/three/expand_aabb_by_transformed_three_object.js +4 -4
- package/src/engine/graphics/trail/x/RibbonX.js +26 -5
- package/src/engine/sound/ecs/emitter/SoundEmitter.js +18 -16
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +3 -5
- package/src/core/bvh2/binary/tiny/TinyBVH.js +0 -221
- package/src/engine/graphics/ecs/camera/CameraClippingPlaneComputer.js +0 -138
|
@@ -63,6 +63,60 @@ test('read/write 1 leaf', () => {
|
|
|
63
63
|
expect(bounds[5]).toBeCloseTo(23);
|
|
64
64
|
});
|
|
65
65
|
|
|
66
|
+
test("2 leaf node build", () => {
|
|
67
|
+
const bvh = new BinaryUint32BVH();
|
|
68
|
+
|
|
69
|
+
bvh.setLeafCount(2);
|
|
70
|
+
bvh.initialize_structure();
|
|
71
|
+
|
|
72
|
+
bvh.setLeafData(0, 3, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
|
|
73
|
+
bvh.setLeafData(1, 7, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6);
|
|
74
|
+
|
|
75
|
+
bvh.build();
|
|
76
|
+
|
|
77
|
+
const bounds = [];
|
|
78
|
+
|
|
79
|
+
bvh.readBounds(0, bounds, 0);
|
|
80
|
+
|
|
81
|
+
expect(bounds).toEqual(Array.from(new Float32Array([0.1, 0.2, 0.3, 1.4, 1.5, 1.6])));
|
|
82
|
+
});
|
|
83
|
+
|
|
84
|
+
test("1 leaf node build", () => {
|
|
85
|
+
const bvh = new BinaryUint32BVH();
|
|
86
|
+
|
|
87
|
+
bvh.setLeafCount(1);
|
|
88
|
+
bvh.initialize_structure();
|
|
89
|
+
|
|
90
|
+
bvh.setLeafData(0, 3, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
|
|
91
|
+
|
|
92
|
+
bvh.build();
|
|
93
|
+
|
|
94
|
+
const bounds = [];
|
|
95
|
+
|
|
96
|
+
bvh.readBounds(0, bounds, 0);
|
|
97
|
+
|
|
98
|
+
expect(bounds).toEqual(Array.from(new Float32Array([0.1, 0.2, 0.3, 0.4, 0.5, 0.6])));
|
|
99
|
+
});
|
|
100
|
+
|
|
101
|
+
test("3 leaf node build", () => {
|
|
102
|
+
const bvh = new BinaryUint32BVH();
|
|
103
|
+
|
|
104
|
+
bvh.setLeafCount(3);
|
|
105
|
+
bvh.initialize_structure();
|
|
106
|
+
|
|
107
|
+
bvh.setLeafData(0, 3, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6);
|
|
108
|
+
bvh.setLeafData(1, 7, 1.1, 1.2, 1.3, 1.4, 1.5, 1.6);
|
|
109
|
+
bvh.setLeafData(2, 11, 2.1, 2.2, 2.3, 2.4, 2.5, 2.6);
|
|
110
|
+
|
|
111
|
+
bvh.build();
|
|
112
|
+
|
|
113
|
+
const bounds = [];
|
|
114
|
+
|
|
115
|
+
bvh.readBounds(0, bounds, 0);
|
|
116
|
+
|
|
117
|
+
expect(bounds).toEqual(Array.from(new Float32Array([0.1, 0.2, 0.3, 2.4, 2.5, 2.6])));
|
|
118
|
+
});
|
|
119
|
+
|
|
66
120
|
test('4 node sorted build', () => {
|
|
67
121
|
const bvh = new BinaryUint32BVH();
|
|
68
122
|
|
|
@@ -0,0 +1,98 @@
|
|
|
1
|
+
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
2
|
+
import { aabb3_array_intersects_ray } from "../../../geom/3d/aabb/aabb3_array_intersects_ray.js";
|
|
3
|
+
import { BVH_BINARY_NODE_SIZE, BVH_LEAF_NODE_SIZE } from "./BinaryUint32BVH.js";
|
|
4
|
+
|
|
5
|
+
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @param {BinaryUint32BVH} bvh
|
|
10
|
+
* @param {number[]} result
|
|
11
|
+
* @param {number} result_offset
|
|
12
|
+
* @param {number} origin_x
|
|
13
|
+
* @param {number} origin_y
|
|
14
|
+
* @param {number} origin_z
|
|
15
|
+
* @param {number} direction_x
|
|
16
|
+
* @param {number} direction_y
|
|
17
|
+
* @param {number} direction_z
|
|
18
|
+
* @returns {number}
|
|
19
|
+
*/
|
|
20
|
+
export function bvh32_query_user_data_ray(
|
|
21
|
+
bvh,
|
|
22
|
+
result, result_offset,
|
|
23
|
+
origin_x, origin_y, origin_z,
|
|
24
|
+
direction_x, direction_y, direction_z
|
|
25
|
+
) {
|
|
26
|
+
let hit_count = 0;
|
|
27
|
+
|
|
28
|
+
const binary_node_count = bvh.getBinaryNodeCount();
|
|
29
|
+
|
|
30
|
+
if (binary_node_count <= 0) {
|
|
31
|
+
// this should not happen
|
|
32
|
+
return 0;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/**
|
|
36
|
+
*
|
|
37
|
+
* @type {number}
|
|
38
|
+
*/
|
|
39
|
+
const stack_top = stack.pointer++;
|
|
40
|
+
|
|
41
|
+
/**
|
|
42
|
+
* After performing empirical tests, stack-based depth-first traversal turns out faster than using a queue
|
|
43
|
+
* @type {number}
|
|
44
|
+
*/
|
|
45
|
+
stack[stack_top] = 0;
|
|
46
|
+
|
|
47
|
+
const last_valid_index = binary_node_count + bvh.getLeafNodeCount();
|
|
48
|
+
|
|
49
|
+
const float32 = bvh.float32;
|
|
50
|
+
const uint32 = bvh.uint32;
|
|
51
|
+
|
|
52
|
+
do {
|
|
53
|
+
stack.pointer--;
|
|
54
|
+
|
|
55
|
+
// query_bvh_frustum_from_objects.iteration_count++;
|
|
56
|
+
const node_index = stack[stack.pointer];
|
|
57
|
+
|
|
58
|
+
if (node_index < binary_node_count) {
|
|
59
|
+
// is intermediate node
|
|
60
|
+
const node_address = node_index * BVH_BINARY_NODE_SIZE;
|
|
61
|
+
|
|
62
|
+
if (!aabb3_array_intersects_ray(
|
|
63
|
+
float32, node_address,
|
|
64
|
+
origin_x, origin_y, origin_z,
|
|
65
|
+
direction_x, direction_y, direction_z
|
|
66
|
+
)) {
|
|
67
|
+
continue;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
const left_index = (node_index << 1) + 1;
|
|
71
|
+
const right_index = left_index + 1;
|
|
72
|
+
|
|
73
|
+
// left node ends up on top of the stack, which aligns with the desired access sequence
|
|
74
|
+
if (right_index < last_valid_index) {
|
|
75
|
+
stack[stack.pointer++] = right_index;
|
|
76
|
+
// micro-optimization, since we know that right node is valid and left appears before that, left is valid too
|
|
77
|
+
stack[stack.pointer++] = left_index;
|
|
78
|
+
} else if (left_index < last_valid_index) {
|
|
79
|
+
stack[stack.pointer++] = left_index;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
} else {
|
|
84
|
+
// leaf node
|
|
85
|
+
const leaf_index = node_index - binary_node_count;
|
|
86
|
+
|
|
87
|
+
const node_address = leaf_index * BVH_LEAF_NODE_SIZE + binary_node_count * BVH_BINARY_NODE_SIZE;
|
|
88
|
+
|
|
89
|
+
// write to output
|
|
90
|
+
result[result_offset + hit_count] = uint32[node_address + 6];
|
|
91
|
+
|
|
92
|
+
hit_count++;
|
|
93
|
+
}
|
|
94
|
+
|
|
95
|
+
} while (stack.pointer > stack_top)
|
|
96
|
+
|
|
97
|
+
return hit_count;
|
|
98
|
+
}
|
|
@@ -58,7 +58,7 @@ const INITIAL_CAPACITY = 128;
|
|
|
58
58
|
* @see https://blog.dashlane.com/how-is-data-stored-in-v8-js-engine-memory
|
|
59
59
|
* @class
|
|
60
60
|
*/
|
|
61
|
-
export class
|
|
61
|
+
export class BVH {
|
|
62
62
|
|
|
63
63
|
/**
|
|
64
64
|
*
|
|
@@ -993,7 +993,7 @@ export class ExplicitBinaryBoundingVolumeHierarchy {
|
|
|
993
993
|
|
|
994
994
|
/**
|
|
995
995
|
*
|
|
996
|
-
* @param {function(node:number, tree:
|
|
996
|
+
* @param {function(node:number, tree:BVH):void} callback
|
|
997
997
|
* @param {*} [ctx]
|
|
998
998
|
*/
|
|
999
999
|
traverse(callback, ctx) {
|
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BVH, NULL_NODE } from "./BVH.js";
|
|
2
2
|
|
|
3
3
|
test("constructor doesn't throw", () => {
|
|
4
|
-
expect(() => new
|
|
4
|
+
expect(() => new BVH()).not.toThrow();
|
|
5
5
|
});
|
|
6
6
|
|
|
7
7
|
test("initial root is NULL", () => {
|
|
8
|
-
const bvh = new
|
|
8
|
+
const bvh = new BVH();
|
|
9
9
|
|
|
10
10
|
expect(bvh.root).toBe(NULL_NODE);
|
|
11
11
|
});
|
|
12
12
|
|
|
13
13
|
test("allocate a node", () => {
|
|
14
|
-
const bvh = new
|
|
14
|
+
const bvh = new BVH();
|
|
15
15
|
|
|
16
16
|
const id = bvh.allocate_node();
|
|
17
17
|
|
|
@@ -21,7 +21,7 @@ test("allocate a node", () => {
|
|
|
21
21
|
});
|
|
22
22
|
|
|
23
23
|
test("set/get aabb", () => {
|
|
24
|
-
const bvh = new
|
|
24
|
+
const bvh = new BVH();
|
|
25
25
|
|
|
26
26
|
const node = bvh.allocate_node();
|
|
27
27
|
|
|
@@ -37,7 +37,7 @@ test("set/get aabb", () => {
|
|
|
37
37
|
});
|
|
38
38
|
|
|
39
39
|
test("insert one leaf", () => {
|
|
40
|
-
const bvh = new
|
|
40
|
+
const bvh = new BVH();
|
|
41
41
|
|
|
42
42
|
const node = bvh.allocate_node();
|
|
43
43
|
|
|
@@ -48,7 +48,7 @@ test("insert one leaf", () => {
|
|
|
48
48
|
|
|
49
49
|
test("node reuse after de-allocation", () => {
|
|
50
50
|
|
|
51
|
-
const bvh = new
|
|
51
|
+
const bvh = new BVH();
|
|
52
52
|
|
|
53
53
|
const a = bvh.allocate_node();
|
|
54
54
|
|
|
@@ -61,7 +61,7 @@ test("node reuse after de-allocation", () => {
|
|
|
61
61
|
|
|
62
62
|
test("insert two leaves", () => {
|
|
63
63
|
|
|
64
|
-
const bvh = new
|
|
64
|
+
const bvh = new BVH();
|
|
65
65
|
|
|
66
66
|
const a = bvh.allocate_node();
|
|
67
67
|
bvh.insert_leaf(a);
|
|
@@ -79,7 +79,7 @@ test("insert two leaves", () => {
|
|
|
79
79
|
|
|
80
80
|
test("set/get user data", () => {
|
|
81
81
|
|
|
82
|
-
const bvh = new
|
|
82
|
+
const bvh = new BVH();
|
|
83
83
|
|
|
84
84
|
const a = bvh.allocate_node();
|
|
85
85
|
|
|
@@ -89,7 +89,7 @@ test("set/get user data", () => {
|
|
|
89
89
|
});
|
|
90
90
|
|
|
91
91
|
test("remove single leaf", () => {
|
|
92
|
-
const bvh = new
|
|
92
|
+
const bvh = new BVH();
|
|
93
93
|
|
|
94
94
|
const a = bvh.allocate_node();
|
|
95
95
|
bvh.insert_leaf(a);
|
|
@@ -104,7 +104,7 @@ test("remove single leaf", () => {
|
|
|
104
104
|
|
|
105
105
|
test("add and remove 5 nodes", () => {
|
|
106
106
|
|
|
107
|
-
const bvh = new
|
|
107
|
+
const bvh = new BVH();
|
|
108
108
|
|
|
109
109
|
const leaves = [];
|
|
110
110
|
const removed_leaves = [];
|
|
@@ -146,13 +146,13 @@ test("add and remove 5 nodes", () => {
|
|
|
146
146
|
|
|
147
147
|
|
|
148
148
|
test("release_all from empty doesn't throw", () => {
|
|
149
|
-
const bvh = new
|
|
149
|
+
const bvh = new BVH();
|
|
150
150
|
|
|
151
151
|
expect(() => bvh.release_all()).not.toThrow();
|
|
152
152
|
});
|
|
153
153
|
|
|
154
154
|
test("release_all with 1 leaf", () => {
|
|
155
|
-
const bvh = new
|
|
155
|
+
const bvh = new BVH();
|
|
156
156
|
|
|
157
157
|
const a = bvh.allocate_node();
|
|
158
158
|
|
|
@@ -164,7 +164,7 @@ test("release_all with 1 leaf", () => {
|
|
|
164
164
|
});
|
|
165
165
|
|
|
166
166
|
test("capacity grows as necessary when allocating", () => {
|
|
167
|
-
const bvh = new
|
|
167
|
+
const bvh = new BVH();
|
|
168
168
|
|
|
169
169
|
bvh.node_capacity = 1;
|
|
170
170
|
|
|
@@ -176,7 +176,7 @@ test("capacity grows as necessary when allocating", () => {
|
|
|
176
176
|
});
|
|
177
177
|
|
|
178
178
|
test("trim sets capacity to exact allocated size", () => {
|
|
179
|
-
const bvh = new
|
|
179
|
+
const bvh = new BVH();
|
|
180
180
|
|
|
181
181
|
bvh.node_capacity = 1;
|
|
182
182
|
|
|
@@ -192,7 +192,7 @@ test("trim sets capacity to exact allocated size", () => {
|
|
|
192
192
|
|
|
193
193
|
test("node property setters/getters", () => {
|
|
194
194
|
|
|
195
|
-
const bvh = new
|
|
195
|
+
const bvh = new BVH();
|
|
196
196
|
|
|
197
197
|
const node = bvh.allocate_node();
|
|
198
198
|
|
|
@@ -221,7 +221,7 @@ test("node property setters/getters", () => {
|
|
|
221
221
|
|
|
222
222
|
|
|
223
223
|
test("node_set_aabb_primitive", () => {
|
|
224
|
-
const bvh = new
|
|
224
|
+
const bvh = new BVH();
|
|
225
225
|
|
|
226
226
|
const node = bvh.allocate_node();
|
|
227
227
|
|
|
@@ -235,7 +235,7 @@ test("node_set_aabb_primitive", () => {
|
|
|
235
235
|
});
|
|
236
236
|
|
|
237
237
|
test("swap two detached nodes", () => {
|
|
238
|
-
const bvh = new
|
|
238
|
+
const bvh = new BVH();
|
|
239
239
|
|
|
240
240
|
const a = bvh.allocate_node();
|
|
241
241
|
const b = bvh.allocate_node();
|
|
@@ -250,7 +250,7 @@ test("swap two detached nodes", () => {
|
|
|
250
250
|
});
|
|
251
251
|
|
|
252
252
|
test("setting capacity", () => {
|
|
253
|
-
const bvh = new
|
|
253
|
+
const bvh = new BVH();
|
|
254
254
|
|
|
255
255
|
bvh.node_capacity = 3;
|
|
256
256
|
|
|
@@ -278,7 +278,7 @@ test("setting capacity", () => {
|
|
|
278
278
|
});
|
|
279
279
|
|
|
280
280
|
test("move leaf node", () => {
|
|
281
|
-
const bvh = new
|
|
281
|
+
const bvh = new BVH();
|
|
282
282
|
|
|
283
283
|
const a = bvh.allocate_node();
|
|
284
284
|
const b = bvh.allocate_node();
|
|
@@ -1,12 +1,13 @@
|
|
|
1
1
|
import { assert } from "../../assert.js";
|
|
2
|
+
import { aabb3_array_set } from "../../geom/3d/aabb/aabb3_array_set.js";
|
|
2
3
|
|
|
3
4
|
/**
|
|
4
5
|
* A convenience class to work with BVH leaf nodes
|
|
5
6
|
*/
|
|
6
|
-
export class
|
|
7
|
+
export class BvhClient {
|
|
7
8
|
/**
|
|
8
9
|
*
|
|
9
|
-
* @type {
|
|
10
|
+
* @type {BVH|null}
|
|
10
11
|
*/
|
|
11
12
|
#tree = null;
|
|
12
13
|
|
|
@@ -28,7 +29,7 @@ export class EBBVHLeafProxy {
|
|
|
28
29
|
|
|
29
30
|
/**
|
|
30
31
|
*
|
|
31
|
-
* @param {
|
|
32
|
+
* @param {BVH} tree
|
|
32
33
|
* @param {number} data Must be a uint32
|
|
33
34
|
*/
|
|
34
35
|
link(tree, data) {
|
|
@@ -67,4 +68,22 @@ export class EBBVHLeafProxy {
|
|
|
67
68
|
|
|
68
69
|
this.#tree.node_move_aabb(this.#node_id, this.bounds);
|
|
69
70
|
}
|
|
71
|
+
|
|
72
|
+
/**
|
|
73
|
+
*
|
|
74
|
+
* @param {number} x0
|
|
75
|
+
* @param {number} y0
|
|
76
|
+
* @param {number} z0
|
|
77
|
+
* @param {number} x1
|
|
78
|
+
* @param {number} y1
|
|
79
|
+
* @param {number} z1
|
|
80
|
+
*/
|
|
81
|
+
resize(x0, y0, z0, x1, y1, z1) {
|
|
82
|
+
aabb3_array_set(
|
|
83
|
+
this.bounds, 0,
|
|
84
|
+
x0, y0, z0, x1, y1, z1
|
|
85
|
+
);
|
|
86
|
+
|
|
87
|
+
this.write_bounds();
|
|
88
|
+
}
|
|
70
89
|
}
|
|
@@ -0,0 +1,51 @@
|
|
|
1
|
+
import { BVH } from "./BVH.js";
|
|
2
|
+
import { BvhClient } from "./BvhClient.js";
|
|
3
|
+
import { bvh_query_leaves_generic } from "./query/bvh_query_leaves_generic.js";
|
|
4
|
+
import { BVHQueryAny } from "./query/BVHQueryAny.js";
|
|
5
|
+
|
|
6
|
+
test("connect/disconnect", () => {
|
|
7
|
+
|
|
8
|
+
const client = new BvhClient();
|
|
9
|
+
|
|
10
|
+
const bvh = new BVH();
|
|
11
|
+
|
|
12
|
+
client.bounds[0] = 2
|
|
13
|
+
client.bounds[1] = 3
|
|
14
|
+
client.bounds[2] = 5
|
|
15
|
+
client.bounds[3] = 7
|
|
16
|
+
client.bounds[4] = 11
|
|
17
|
+
client.bounds[5] = 13
|
|
18
|
+
|
|
19
|
+
expect(client.is_linked).toBe(false);
|
|
20
|
+
|
|
21
|
+
client.link(bvh, 17);
|
|
22
|
+
|
|
23
|
+
expect(client.is_linked).toBe(true);
|
|
24
|
+
|
|
25
|
+
const leaves = [];
|
|
26
|
+
bvh_query_leaves_generic(leaves, 0, bvh, bvh.root, BVHQueryAny.INSTANCE);
|
|
27
|
+
|
|
28
|
+
expect(leaves.length).toEqual(1);
|
|
29
|
+
|
|
30
|
+
const leaf = leaves[0];
|
|
31
|
+
|
|
32
|
+
expect(bvh.node_get_user_data(leaf)).toEqual(17);
|
|
33
|
+
|
|
34
|
+
const aabb = [];
|
|
35
|
+
|
|
36
|
+
bvh.node_get_aabb(leaf, aabb);
|
|
37
|
+
|
|
38
|
+
expect(aabb).toEqual(Array.from(client.bounds));
|
|
39
|
+
|
|
40
|
+
// disconnect
|
|
41
|
+
client.unlink();
|
|
42
|
+
|
|
43
|
+
expect(client.is_linked).toBe(false);
|
|
44
|
+
|
|
45
|
+
expect(bvh_query_leaves_generic(
|
|
46
|
+
leaves, 0,
|
|
47
|
+
bvh, bvh.root,
|
|
48
|
+
BVHQueryAny.INSTANCE
|
|
49
|
+
))
|
|
50
|
+
.toBe(0);
|
|
51
|
+
});
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { min2 } from "../../math/min2.js";
|
|
2
1
|
import { compute_triangle_group_aabb3 } from "../../../engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.js";
|
|
2
|
+
import { min2 } from "../../math/min2.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
5
5
|
* Build the BVH by relying on BVH's own incremental insertion mechanism
|
|
6
|
-
* @param {
|
|
6
|
+
* @param {BVH} bvh
|
|
7
7
|
* @param {number[]|Float32Array} index_array
|
|
8
8
|
* @param {number[]|Float32Array} positions_array
|
|
9
9
|
* @param {number} [batch_size] can batch triangles in groups of up-to this many triangles per BVH leaf
|
|
@@ -1,15 +1,15 @@
|
|
|
1
|
+
import { compute_triangle_group_aabb3 } from "../../../engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.js";
|
|
2
|
+
import { arrayQuickSort } from "../../collection/array/arrayQuickSort.js";
|
|
1
3
|
import { AABB3 } from "../../geom/3d/aabb/AABB3.js";
|
|
2
4
|
import { aabb3_from_v3_array } from "../../geom/3d/aabb/aabb3_from_v3_array.js";
|
|
3
5
|
import morton from "../../geom/3d/morton/Morton.js";
|
|
4
|
-
import { arrayQuickSort } from "../../collection/array/arrayQuickSort.js";
|
|
5
|
-
import { compute_triangle_group_aabb3 } from "../../../engine/graphics/sh3/path_tracer/compute_triangle_group_aabb3.js";
|
|
6
|
-
import { NULL_NODE } from "./ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
7
6
|
import { max2 } from "../../math/max2.js";
|
|
7
|
+
import { NULL_NODE } from "./BVH.js";
|
|
8
8
|
|
|
9
9
|
/**
|
|
10
10
|
* Build the BVH bottom-up using spatial hash sorting
|
|
11
11
|
* Resulting BVH is produced very quickly, has perfect balance and is of decent quality
|
|
12
|
-
* @param {
|
|
12
|
+
* @param {BVH} bvh
|
|
13
13
|
* @param {number[]|Float32Array} index_array
|
|
14
14
|
* @param {number[]|Float32Array} position_array
|
|
15
15
|
*/
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
+
import { BVH, NULL_NODE } from "./BVH.js";
|
|
1
2
|
import { ebvh_build_for_geometry_morton } from "./ebvh_build_for_geometry_morton.js";
|
|
2
|
-
import { ExplicitBinaryBoundingVolumeHierarchy, NULL_NODE } from "./ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
3
3
|
|
|
4
4
|
test("sanity check with 1 triangle", () => {
|
|
5
5
|
|
|
6
|
-
const bvh = new
|
|
6
|
+
const bvh = new BVH();
|
|
7
7
|
|
|
8
8
|
ebvh_build_for_geometry_morton(bvh, [0, 1, 2], [
|
|
9
9
|
0, 1, 3,
|
|
@@ -29,7 +29,7 @@ test("sanity check with 1 triangle", () => {
|
|
|
29
29
|
});
|
|
30
30
|
|
|
31
31
|
test("sanity check with 2 triangles", () => {
|
|
32
|
-
const bvh = new
|
|
32
|
+
const bvh = new BVH();
|
|
33
33
|
|
|
34
34
|
ebvh_build_for_geometry_morton(
|
|
35
35
|
bvh,
|
|
@@ -1,16 +1,10 @@
|
|
|
1
|
-
import {
|
|
2
|
-
COLUMN_CHILD_1,
|
|
3
|
-
COLUMN_HEIGHT,
|
|
4
|
-
COLUMN_PARENT,
|
|
5
|
-
ELEMENT_WORD_COUNT,
|
|
6
|
-
NULL_NODE
|
|
7
|
-
} from "./ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
1
|
+
import { COLUMN_CHILD_1, COLUMN_HEIGHT, COLUMN_PARENT, ELEMENT_WORD_COUNT, NULL_NODE } from "./BVH.js";
|
|
8
2
|
|
|
9
3
|
/**
|
|
10
4
|
* Sort live nodes in the traversal order.
|
|
11
5
|
* This makes most queries have linear access, resulting in near-optimal cache usage
|
|
12
6
|
* NOTE: assumes that there are no free nodes
|
|
13
|
-
* @param {
|
|
7
|
+
* @param {BVH} bvh
|
|
14
8
|
*/
|
|
15
9
|
export function ebvh_sort_for_traversal_depth_first(bvh) {
|
|
16
10
|
const stack = [];
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
//
|
|
2
2
|
|
|
3
|
-
import { NULL_NODE } from "../ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
4
3
|
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
4
|
+
import { NULL_NODE } from "../BVH.js";
|
|
5
5
|
|
|
6
6
|
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
7
7
|
|
|
@@ -9,7 +9,7 @@ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
|
9
9
|
*
|
|
10
10
|
* @param {number[]} destination
|
|
11
11
|
* @param {number} destination_offset
|
|
12
|
-
* @param {
|
|
12
|
+
* @param {BVH} bvh
|
|
13
13
|
* @param {number} root
|
|
14
14
|
* @returns {number} number of collected elements
|
|
15
15
|
*/
|
|
@@ -1,11 +1,11 @@
|
|
|
1
|
-
import { NULL_NODE } from "../ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
2
1
|
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
2
|
+
import { NULL_NODE } from "../BVH.js";
|
|
3
3
|
|
|
4
4
|
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
|
-
* @param {
|
|
8
|
+
* @param {BVH} bvh
|
|
9
9
|
* @param {number[]} result
|
|
10
10
|
* @param {number} result_offset
|
|
11
11
|
* @param {number} root
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BVH } from "../BVH.js";
|
|
2
2
|
import { bvh_query_leaves_generic } from "./bvh_query_leaves_generic.js";
|
|
3
3
|
import { BVHQueryAny } from "./BVHQueryAny.js";
|
|
4
4
|
|
|
5
5
|
test("all-accepting query", () => {
|
|
6
|
-
const bvh = new
|
|
6
|
+
const bvh = new BVH();
|
|
7
7
|
|
|
8
8
|
const leaf_a = bvh.allocate_node();
|
|
9
9
|
const leaf_b = bvh.allocate_node();
|
|
@@ -1,18 +1,13 @@
|
|
|
1
|
-
import { aabb3_intersects_ray } from "../../../geom/3d/aabb/aabb3_intersects_ray.js";
|
|
2
|
-
import {
|
|
3
|
-
COLUMN_CHILD_1,
|
|
4
|
-
COLUMN_CHILD_2,
|
|
5
|
-
ELEMENT_WORD_COUNT,
|
|
6
|
-
NULL_NODE
|
|
7
|
-
} from "../ExplicitBinaryBoundingVolumeHierarchy.js";
|
|
8
1
|
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
2
|
+
import { aabb3_intersects_ray } from "../../../geom/3d/aabb/aabb3_intersects_ray.js";
|
|
3
|
+
import { COLUMN_CHILD_1, COLUMN_CHILD_2, ELEMENT_WORD_COUNT, NULL_NODE } from "../BVH.js";
|
|
9
4
|
|
|
10
5
|
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
11
6
|
|
|
12
7
|
|
|
13
8
|
/**
|
|
14
9
|
*
|
|
15
|
-
* @param {
|
|
10
|
+
* @param {BVH} bvh
|
|
16
11
|
* @param {number} root
|
|
17
12
|
* @param {number[]} result
|
|
18
13
|
* @param {number} result_offset
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BVH } from "../BVH.js";
|
|
2
2
|
import { bvh_query_leaves_ray } from "./bvh_query_leaves_ray.js";
|
|
3
3
|
|
|
4
4
|
/**
|
|
@@ -7,7 +7,7 @@ import { bvh_query_leaves_ray } from "./bvh_query_leaves_ray.js";
|
|
|
7
7
|
*/
|
|
8
8
|
function makeBVH(...leaves) {
|
|
9
9
|
|
|
10
|
-
const bvh = new
|
|
10
|
+
const bvh = new BVH();
|
|
11
11
|
|
|
12
12
|
for (let i = 0; i < leaves.length; i++) {
|
|
13
13
|
|
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
import { assert } from "../../../assert.js";
|
|
2
2
|
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
3
|
-
import { NULL_NODE } from "../
|
|
3
|
+
import { NULL_NODE } from "../BVH.js";
|
|
4
4
|
|
|
5
5
|
const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
6
6
|
|
|
7
7
|
|
|
8
8
|
/**
|
|
9
9
|
*
|
|
10
|
-
* @param {
|
|
10
|
+
* @param {BVH} bvh
|
|
11
11
|
* @param {number[]} result
|
|
12
12
|
* @param {number} result_offset
|
|
13
13
|
* @param {number} root
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { BVH } from "../BVH.js";
|
|
2
2
|
import { bvh_query_user_data_generic } from "./bvh_query_user_data_generic.js";
|
|
3
3
|
import { BVHQueryAny } from "./BVHQueryAny.js";
|
|
4
4
|
|
|
5
5
|
test("all-accepting query", () => {
|
|
6
|
-
const bvh = new
|
|
6
|
+
const bvh = new BVH();
|
|
7
7
|
|
|
8
8
|
const leaf_a = bvh.allocate_node();
|
|
9
9
|
const leaf_b = bvh.allocate_node();
|
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { SCRATCH_UINT32_TRAVERSAL_STACK } from "../../../collection/SCRATCH_UINT32_TRAVERSAL_STACK.js";
|
|
2
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
|
-
import {
|
|
4
|
+
import { NULL_NODE } from "../BVH.js";
|
|
5
5
|
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
@@ -13,7 +13,7 @@ const stack = SCRATCH_UINT32_TRAVERSAL_STACK;
|
|
|
13
13
|
|
|
14
14
|
/**
|
|
15
15
|
*
|
|
16
|
-
* @param {
|
|
16
|
+
* @param {BVH} bvh
|
|
17
17
|
* @param {number} x
|
|
18
18
|
* @param {number} y
|
|
19
19
|
* @param {number} z
|