@woosh/meep-engine 2.63.0 → 2.65.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/meep.cjs +5357 -5350
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +5357 -5350
- package/package.json +1 -1
- package/src/core/binary/UINT16_MAX.js +5 -0
- package/src/core/bvh2/BinaryNode.js +14 -14
- package/src/core/bvh2/LeafNode.js +4 -4
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.d.ts → BVH.d.ts} +1 -1
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.js → BVH.js} +7 -7
- package/src/core/bvh2/bvh3/{ExplicitBinaryBoundingVolumeHierarchy.spec.js → BVH.spec.js} +20 -20
- package/src/core/bvh2/bvh3/{EBBVHLeafProxy.js → BvhClient.js} +3 -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/BVHQueryIntersectsFrustum.js +8 -10
- package/src/core/bvh2/bvh3/query/BVHQueryIntersectsRay.js +7 -7
- package/src/core/bvh2/bvh3/query/BVHQueryIntersectsSphere.js +37 -0
- 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 +13 -5
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_generic.spec.js +29 -0
- 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/list/List.js +9 -3
- package/src/core/geom/3d/aabb/aabb3_from_v3_array.js +11 -4
- package/src/core/geom/Vector2.js +6 -4
- package/src/engine/graphics/ecs/decal/v2/FPDecalSystem.js +22 -24
- package/src/engine/graphics/ecs/mesh/Mesh.js +8 -8
- package/src/engine/graphics/ecs/mesh/MeshSystem.js +3 -5
- 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/particles/particular/engine/ParticularEngine.js +9 -11
- package/src/engine/graphics/particles/particular/engine/emitter/ParticleEmitter.js +51 -88
- package/src/engine/graphics/particles/particular/engine/emitter/ParticlePool.js +41 -72
- package/src/engine/graphics/particles/particular/engine/emitter/write_particle_patch_uv.js +28 -0
- 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/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/sound/ecs/emitter/SoundEmitter.js +18 -16
- package/src/engine/sound/ecs/emitter/SoundEmitterSystem.js +20 -22
- package/src/core/bvh2/bvh3/query/bvh_query_user_data_overlaps_sphere.js +0 -81
- package/src/engine/ecs/foliage/Foliage.js +0 -151
- package/src/engine/ecs/foliage/FoliageLoader.js +0 -39
- package/src/engine/ecs/foliage/FoliageVisibilitySetBuilder.js +0 -27
- package/src/engine/ecs/foliage/ImpostorFoliage.js +0 -106
- package/src/engine/ecs/foliage/InstancedFoliage.js +0 -395
- package/src/engine/ecs/foliage/ViewState.js +0 -181
- package/src/engine/ecs/foliage/ecs/Foliage2System.js +0 -333
- package/src/engine/ecs/foliage/ecs/InstancedMeshComponent.js +0 -70
- package/src/engine/ecs/foliage/ecs/InstancedMeshLayer.js +0 -138
- package/src/engine/ecs/foliage/ecs/InstancedMeshSerializationAdapter.js +0 -28
- package/src/engine/ecs/foliage/ecs/convertInstancedMeshComponents2Entities.js +0 -64
- package/src/engine/ecs/foliage/ecs/optimizeIndividualMeshesEntitiesToInstances.js +0 -233
- package/src/engine/save/storage/GooglePlayStorage.js +0 -47
- package/src/engine/save/storage/JsonStringCodec.js +0 -24
- /package/src/engine/sound/ecs/emitter/{SoundEmitter.spec.js → SoundEmitterSerializationAdapter.spec.js} +0 -0
package/package.json
CHANGED
|
@@ -3,19 +3,19 @@
|
|
|
3
3
|
*/
|
|
4
4
|
|
|
5
5
|
|
|
6
|
-
import {assert} from "../assert.js";
|
|
7
|
-
import {arrayQuickSort} from "../collection/array/arrayQuickSort.js";
|
|
8
|
-
import {aabb3_box_surface_area_2} from "../geom/3d/aabb/aabb3_box_surface_area_2.js";
|
|
9
|
-
import {aabb3_combined_surface_area} from "../geom/3d/aabb/aabb3_combined_surface_area.js";
|
|
10
|
-
import {aabb3_intersects_aabb3} from "../geom/3d/aabb/aabb3_intersects_aabb3.js";
|
|
11
|
-
import {max2} from "../math/max2.js";
|
|
12
|
-
import {min2} from "../math/min2.js";
|
|
13
|
-
import {computeSampleStandardDeviation} from "../math/statistics/computeSampleStandardDeviation.js";
|
|
14
|
-
import {isLeaf, LeafNode} from "./LeafNode.js";
|
|
15
|
-
import {Node} from "./Node.js";
|
|
16
|
-
import {surfaceAreaHeuristic} from "./sah/surfaceAreaHeuristic.js";
|
|
17
|
-
import {BVHVisitor} from "./traversal/BVHVisitor.js";
|
|
18
|
-
import {traverseBinaryNodeUsingVisitor} from "./traversal/traverseBinaryNodeUsingVisitor.js";
|
|
6
|
+
import { assert } from "../assert.js";
|
|
7
|
+
import { arrayQuickSort } from "../collection/array/arrayQuickSort.js";
|
|
8
|
+
import { aabb3_box_surface_area_2 } from "../geom/3d/aabb/aabb3_box_surface_area_2.js";
|
|
9
|
+
import { aabb3_combined_surface_area } from "../geom/3d/aabb/aabb3_combined_surface_area.js";
|
|
10
|
+
import { aabb3_intersects_aabb3 } from "../geom/3d/aabb/aabb3_intersects_aabb3.js";
|
|
11
|
+
import { max2 } from "../math/max2.js";
|
|
12
|
+
import { min2 } from "../math/min2.js";
|
|
13
|
+
import { computeSampleStandardDeviation } from "../math/statistics/computeSampleStandardDeviation.js";
|
|
14
|
+
import { isLeaf, LeafNode } from "./LeafNode.js";
|
|
15
|
+
import { Node } from "./Node.js";
|
|
16
|
+
import { surfaceAreaHeuristic } from "./sah/surfaceAreaHeuristic.js";
|
|
17
|
+
import { BVHVisitor } from "./traversal/BVHVisitor.js";
|
|
18
|
+
import { traverseBinaryNodeUsingVisitor } from "./traversal/traverseBinaryNodeUsingVisitor.js";
|
|
19
19
|
|
|
20
20
|
|
|
21
21
|
/**
|
|
@@ -37,7 +37,7 @@ let stackPointer = 0;
|
|
|
37
37
|
const stack = [];
|
|
38
38
|
|
|
39
39
|
/**
|
|
40
|
-
* @deprecated use {@link
|
|
40
|
+
* @deprecated use {@link BVH} instead
|
|
41
41
|
*/
|
|
42
42
|
export class BinaryNode extends Node {
|
|
43
43
|
constructor() {
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Created by Alex on 17/11/2014.
|
|
3
3
|
*/
|
|
4
|
-
import {deserializeAABB3} from "../geom/3d/aabb/deserializeAABB3.js";
|
|
5
|
-
import {serializeAABB3} from "../geom/3d/aabb/serializeAABB3.js";
|
|
6
|
-
import {Node} from "./Node.js";
|
|
4
|
+
import { deserializeAABB3 } from "../geom/3d/aabb/deserializeAABB3.js";
|
|
5
|
+
import { serializeAABB3 } from "../geom/3d/aabb/serializeAABB3.js";
|
|
6
|
+
import { Node } from "./Node.js";
|
|
7
7
|
|
|
8
8
|
|
|
9
9
|
/**
|
|
@@ -16,7 +16,7 @@ function isLeaf(node) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
* @deprecated use {@link
|
|
19
|
+
* @deprecated use {@link BVH} and {@link BvhClient} respectively
|
|
20
20
|
*/
|
|
21
21
|
export class LeafNode extends Node {
|
|
22
22
|
/**
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import { aabb3_compute_surface_area } from "../../geom/3d/aabb/aabb3_compute_surface_area.js";
|
|
2
|
-
import { min2 } from "../../math/min2.js";
|
|
3
|
-
import { max2 } from "../../math/max2.js";
|
|
4
1
|
import { assert } from "../../assert.js";
|
|
5
|
-
import { typed_array_copy } from "../../collection/array/typed/typed_array_copy.js";
|
|
6
2
|
import { array_copy } from "../../collection/array/array_copy.js";
|
|
3
|
+
import { typed_array_copy } from "../../collection/array/typed/typed_array_copy.js";
|
|
4
|
+
import { aabb3_compute_surface_area } from "../../geom/3d/aabb/aabb3_compute_surface_area.js";
|
|
5
|
+
import { max2 } from "../../math/max2.js";
|
|
6
|
+
import { min2 } from "../../math/min2.js";
|
|
7
7
|
|
|
8
8
|
export const COLUMN_PARENT = 6;
|
|
9
9
|
export const COLUMN_CHILD_1 = 7;
|
|
@@ -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
|
*
|
|
@@ -373,7 +373,7 @@ export class ExplicitBinaryBoundingVolumeHierarchy {
|
|
|
373
373
|
/**
|
|
374
374
|
*
|
|
375
375
|
* @param {number} id
|
|
376
|
-
* @param {number[]} result
|
|
376
|
+
* @param {number[]|Float32Array} result
|
|
377
377
|
*/
|
|
378
378
|
node_get_aabb(id, result) {
|
|
379
379
|
assert.isNonNegativeInteger(id, 'id');
|
|
@@ -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();
|
|
@@ -3,10 +3,10 @@ import { assert } from "../../assert.js";
|
|
|
3
3
|
/**
|
|
4
4
|
* A convenience class to work with BVH leaf nodes
|
|
5
5
|
*/
|
|
6
|
-
export class
|
|
6
|
+
export class BvhClient {
|
|
7
7
|
/**
|
|
8
8
|
*
|
|
9
|
-
* @type {
|
|
9
|
+
* @type {BVH|null}
|
|
10
10
|
*/
|
|
11
11
|
#tree = null;
|
|
12
12
|
|
|
@@ -28,7 +28,7 @@ export class EBBVHLeafProxy {
|
|
|
28
28
|
|
|
29
29
|
/**
|
|
30
30
|
*
|
|
31
|
-
* @param {
|
|
31
|
+
* @param {BVH} tree
|
|
32
32
|
* @param {number} data Must be a uint32
|
|
33
33
|
*/
|
|
34
34
|
link(tree, data) {
|
|
@@ -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,18 +1,16 @@
|
|
|
1
|
-
import { BVHQuery } from "./BVHQuery.js";
|
|
2
1
|
import { aabb3_array_intersects_frustum_array } from "../../../geom/3d/aabb/aabb3_array_intersects_frustum_array.js";
|
|
2
|
+
import { BVHQuery } from "./BVHQuery.js";
|
|
3
3
|
|
|
4
4
|
const scratch_aabb = [];
|
|
5
5
|
|
|
6
6
|
export class BVHQueryIntersectsFrustum extends BVHQuery {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
this.frustum = [];
|
|
15
|
-
}
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
* Collection of 6 planes: normal_x, normal_y, normal_z, offset
|
|
10
|
+
* @type {number[]}
|
|
11
|
+
*/
|
|
12
|
+
frustum = [];
|
|
13
|
+
|
|
16
14
|
|
|
17
15
|
/**
|
|
18
16
|
*
|
|
@@ -1,21 +1,21 @@
|
|
|
1
|
-
import { BVHQuery } from "./BVHQuery.js";
|
|
2
1
|
import { aabb3_array_intersects_ray_array } from "../../../geom/3d/aabb/aabb3_array_intersects_ray_array.js";
|
|
2
|
+
import { BVHQuery } from "./BVHQuery.js";
|
|
3
3
|
|
|
4
4
|
const scratch_aabb = [];
|
|
5
5
|
|
|
6
6
|
export class BVHQueryIntersectsRay extends BVHQuery {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
7
|
+
/**
|
|
8
|
+
*
|
|
9
|
+
* @type {number[]}
|
|
10
|
+
*/
|
|
11
|
+
ray = [];
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
*
|
|
15
15
|
* @param {number[]|ArrayLike<number>} ray
|
|
16
16
|
* @returns {BVHQueryIntersectsRay}
|
|
17
17
|
*/
|
|
18
|
-
static from(ray){
|
|
18
|
+
static from(ray) {
|
|
19
19
|
const r = new BVHQueryIntersectsRay();
|
|
20
20
|
|
|
21
21
|
r.ray = ray;
|
|
@@ -0,0 +1,37 @@
|
|
|
1
|
+
import { aabb3_array_intersects_sphere_array } from "../../../geom/3d/aabb/aabb3_array_intersects_sphere_array.js";
|
|
2
|
+
import { BVHQuery } from "./BVHQuery.js";
|
|
3
|
+
|
|
4
|
+
const scratch_aabb = [];
|
|
5
|
+
|
|
6
|
+
export class BVHQueryIntersectsSphere extends BVHQuery {
|
|
7
|
+
|
|
8
|
+
/**
|
|
9
|
+
*
|
|
10
|
+
* @type {number[]}
|
|
11
|
+
*/
|
|
12
|
+
sphere = [];
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
*
|
|
16
|
+
* @param {number[]|ArrayLike<number>} sphere
|
|
17
|
+
* @returns {BVHQueryIntersectsRay}
|
|
18
|
+
*/
|
|
19
|
+
static from(sphere) {
|
|
20
|
+
const r = new BVHQueryIntersectsSphere();
|
|
21
|
+
|
|
22
|
+
r.sphere = sphere;
|
|
23
|
+
|
|
24
|
+
return r;
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
evaluate(node, tree) {
|
|
28
|
+
|
|
29
|
+
tree.node_get_aabb(node, scratch_aabb);
|
|
30
|
+
|
|
31
|
+
// test node against the ray
|
|
32
|
+
return aabb3_array_intersects_sphere_array(
|
|
33
|
+
scratch_aabb,
|
|
34
|
+
this.sphere
|
|
35
|
+
);
|
|
36
|
+
}
|
|
37
|
+
}
|
|
@@ -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
|
|