@woosh/meep-engine 2.67.0 → 2.69.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.
Files changed (87) hide show
  1. package/build/bundle-worker-terrain.js +1 -1
  2. package/build/meep.cjs +698 -1270
  3. package/build/meep.min.js +1 -1
  4. package/build/meep.module.js +698 -1270
  5. package/package.json +1 -1
  6. package/src/core/bvh2/binary/2/BinaryUint32BVH.js +55 -28
  7. package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +3 -3
  8. package/src/core/bvh2/binary/2/bvh32_query_user_data_overlaps_clipping_volume.js +94 -0
  9. package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +17 -18
  10. package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +4 -2
  11. package/src/core/geom/3d/aabb/AABB3.js +14 -14
  12. package/src/core/geom/3d/aabb/aabb3_array_intersects_clipping_volume_array.js +30 -0
  13. package/src/core/geom/3d/aabb/aabb3_intersects_clipping_volume_array.js +51 -0
  14. package/src/core/geom/3d/frustum/{read_frustum_planes_to_array.js → read_three_planes_to_array.js} +5 -3
  15. package/src/core/geom/3d/triangle/triangle_intersects_clipping_volume.js +51 -0
  16. package/src/engine/ecs/terrain/ecs/TerrainSystem.js +2 -2
  17. package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +1 -1
  18. package/src/engine/ecs/terrain/tiles/TerrainTile.js +9 -46
  19. package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -1
  20. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +0 -5
  21. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +0 -1
  22. package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.d.ts +2 -2
  23. package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +79 -36
  24. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_overlap_clipping_volume.js +88 -0
  25. package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js +108 -0
  26. package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +4 -30
  27. package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_unindexed_geometry.js +30 -0
  28. package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +41 -0
  29. package/src/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +16 -19
  30. package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
  31. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +46 -47
  32. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +2 -2
  33. package/src/engine/graphics/render/view/CameraView.js +8 -8
  34. package/src/core/bvh2/BVHTasks.js +0 -65
  35. package/src/core/bvh2/BinaryNode.d.ts +0 -13
  36. package/src/core/bvh2/BinaryNode.js +0 -1188
  37. package/src/core/bvh2/BinaryNode.spec.js +0 -309
  38. package/src/core/bvh2/LeafNode.d.ts +0 -7
  39. package/src/core/bvh2/LeafNode.js +0 -147
  40. package/src/core/bvh2/Node.d.ts +0 -9
  41. package/src/core/bvh2/Node.js +0 -196
  42. package/src/core/bvh2/NodeValidator.js +0 -197
  43. package/src/core/bvh2/StacklessTraverser.js +0 -154
  44. package/src/core/bvh2/StacklessTraverser.spec.js +0 -109
  45. package/src/core/bvh2/binary/BinaryBVH.js +0 -281
  46. package/src/core/bvh2/binary/IndexedBinaryBVH.js +0 -407
  47. package/src/core/bvh2/binary/IndexedBinaryBVH.spec.js +0 -27
  48. package/src/core/bvh2/binary/IndexedBinaryBVHVisitor.js +0 -11
  49. package/src/core/bvh2/binary/NodeType.js +0 -8
  50. package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +0 -59
  51. package/src/core/bvh2/serialization/deserializeBinaryNode.js +0 -40
  52. package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +0 -90
  53. package/src/core/bvh2/serialization/serializeBinaryNode.js +0 -31
  54. package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +0 -86
  55. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +0 -144
  56. package/src/core/bvh2/transform/RotationOptimizer.js +0 -123
  57. package/src/core/bvh2/transform/RotationOptimizer.spec.js +0 -303
  58. package/src/core/bvh2/transform/tryRotateSingleNode.js +0 -260
  59. package/src/core/bvh2/traversal/BVHVisitor.js +0 -30
  60. package/src/core/bvh2/traversal/RaycastBVHVisitor.js +0 -66
  61. package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +0 -384
  62. package/src/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +0 -52
  63. package/src/core/bvh2/traversal/bvh_traverse_pre_order_using_stack.js +0 -43
  64. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.d.ts +0 -5
  65. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.js +0 -66
  66. package/src/core/bvh2/traversal/queryBinaryNode_CollectData.js +0 -49
  67. package/src/core/bvh2/traversal/queryBinaryNode_CollectLeaves.js +0 -51
  68. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +0 -77
  69. package/src/core/bvh2/traversal/queryBinaryNode_SphereIntersections.js +0 -63
  70. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +0 -50
  71. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder.js +0 -34
  72. package/src/core/bvh2/util/find_least_common_ancestor.js +0 -34
  73. package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +0 -50
  74. package/src/core/geom/2d/bvh/BinaryNode2.js +0 -152
  75. package/src/core/geom/2d/bvh/LeafNode2.js +0 -11
  76. package/src/core/geom/2d/bvh/Node2.js +0 -51
  77. package/src/core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js +0 -20
  78. package/src/core/geom/3d/aabb/aabb3_intersects_frustum_array.js +0 -35
  79. package/src/engine/ecs/terrain/tiles/FirstRayIntersectionTerrainBVHVisitor.js +0 -74
  80. package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +0 -195
  81. package/src/engine/graphics/geometry/buffered/query/GeometryVisitor.js +0 -87
  82. package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +0 -206
  83. package/src/engine/graphics/geometry/bvh/BVHFromGeometry.js +0 -72
  84. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +0 -240
  85. package/src/engine/graphics/geometry/bvh/buffered/BinaryBVHFromBufferGeometry.js +0 -123
  86. package/src/engine/graphics/geometry/bvh/buffered/IndexedTraingleBoundsComputer.js +0 -43
  87. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +0 -133
@@ -1,303 +0,0 @@
1
- import { seededRandom } from "../../math/random/seededRandom.js";
2
- import { BinaryNode } from "../BinaryNode.js";
3
- import { isLeaf, LeafNode } from "../LeafNode.js";
4
- import { validateNode, validateTree } from "../NodeValidator.js";
5
- import { optimize } from "./RotationOptimizer.js";
6
-
7
- expect.extend({
8
- toBeValid(node) {
9
- const violations = [];
10
-
11
- function violationCallback(v) {
12
- violations.push(v);
13
- }
14
-
15
- let pass = true;
16
- if (isLeaf(node)) {
17
- pass = pass && validateNode(node, violationCallback);
18
- } else {
19
- pass = pass && validateTree(node, violationCallback);
20
- }
21
-
22
- if (!pass) {
23
- let message = violations.map((v) => v.toString()).join("\n");
24
-
25
- if (message.trim().length === 0) {
26
- message = `node is not valid`;
27
- }
28
-
29
- return {
30
- message: function () {
31
- return message
32
- },
33
- pass: false
34
- };
35
- }
36
-
37
- return {
38
- pass: true
39
- };
40
- },
41
- /**
42
- *
43
- * @param {BinaryNode} container
44
- * @param node
45
- */
46
- toContainNode(container, node) {
47
- let found = false;
48
- let message;
49
- container.traversePreOrderUsingStack(function (n) {
50
- if (n === node) {
51
- found = true;
52
- //stop traversal
53
- return false;
54
- }
55
- });
56
-
57
- if (!found) {
58
- message = `node is not contained within the tree`;
59
- }
60
-
61
- return {
62
- message,
63
- pass: found
64
- };
65
- }
66
- });
67
-
68
- /**
69
- *
70
- * @param {number} v0
71
- * @param {number} v1
72
- * @param {*} [value]
73
- * @returns {LeafNode}
74
- */
75
- function leaf(v0, v1, value) {
76
- const leafNode = new LeafNode(value, v0, v0, v0, v1, v1, v1);
77
- return leafNode;
78
- }
79
-
80
- /**
81
- *
82
- * @param {NodeDescription} left
83
- * @param {NodeDescription} right
84
- * @returns {BinaryNode}
85
- */
86
- function pair(left, right) {
87
- const node = new BinaryNode();
88
-
89
- if (left === null) {
90
- node.right = right;
91
- right.parentNode = node;
92
- node.refit();
93
- } else if (right === null) {
94
- node.left = left;
95
- left.parentNode = left;
96
- node.refit();
97
- } else {
98
- node.setChildren(left, right);
99
- }
100
- return node;
101
- }
102
-
103
-
104
- describe.skip("suite", () => {
105
-
106
-
107
- test("empty node", () => {
108
- const node = new BinaryNode();
109
- node.setInfiniteBounds();
110
-
111
- optimize(node, 100);
112
-
113
- expect(node.left).toBeNull();
114
- expect(node.right).toBeNull();
115
- });
116
-
117
- test("does nothing on optimal 2 child tree", () => {
118
- const a = leaf(0, 1, "hello");
119
- const b = leaf(2, 3, "goodbye");
120
-
121
- const root = pair(a, b);
122
-
123
- const optimized = optimize(root, 100);
124
- expect(optimized).toBe(0);
125
-
126
- //positions preserved
127
- expect(root.left.object).toEqual(a.object);
128
- expect(root.right.object).toEqual(b.object);
129
-
130
- //parent node is root
131
- expect(root.left.parentNode).toEqual(root);
132
- expect(root.right.parentNode).toEqual(root);
133
-
134
- expect(root).toBeValid();
135
- });
136
-
137
- test("does nothing on optimal depth 2 tree", () => {
138
- const a = leaf(-2, -1, "a");
139
- const b = leaf(-1, 0, "b");
140
- const c = leaf(0, 1, "c");
141
- const d = leaf(1, 2, "d");
142
-
143
- const n0 = pair(a, b);
144
- const n1 = pair(c, d);
145
-
146
- const root = pair(n0, n1);
147
-
148
- const optimized = optimize(root, 100);
149
- expect(optimized).toBe(0);
150
-
151
- expect(root.parentNode).toBeNull();
152
-
153
- expect(root.left).toBe(n0);
154
- expect(root.right).toBe(n1);
155
-
156
- expect(n0.left).toBe(a);
157
- expect(n0.right).toBe(b);
158
-
159
- expect(n1.left).toBe(c);
160
- expect(n1.right).toBe(d);
161
-
162
- expect(root).toBeValid();
163
- });
164
-
165
- test("produces a valid tree from left-leaning tree with 4 leaves", () => {
166
- const a = leaf(-2, -1, "a");
167
- const b = leaf(-1, 0, "b");
168
- const c = leaf(0, 1, "c");
169
- const d = leaf(1, 2, "d");
170
-
171
- const root = pair(
172
- pair(
173
- pair(c, d),
174
- b
175
- ),
176
- a
177
- );
178
-
179
- optimize(root, 100);
180
-
181
- expect(root).toBeValid();
182
-
183
- expect(root).toContainNode(a);
184
- expect(root).toContainNode(b);
185
- expect(root).toContainNode(c);
186
- expect(root).toContainNode(d);
187
- });
188
-
189
- test("produces a valid tree from right-leaning tree with 4 leaves", () => {
190
- const a = leaf(-2, -1, "a");
191
- const b = leaf(-1, 0, "b");
192
- const c = leaf(0, 1, "c");
193
- const d = leaf(1, 2, "d");
194
-
195
- const root = pair(
196
- a,
197
- pair(
198
- b,
199
- pair(c, d)
200
- )
201
- );
202
-
203
- optimize(root, 100);
204
-
205
- expect(root).toBeValid();
206
-
207
- expect(root).toContainNode(a);
208
- expect(root).toContainNode(b);
209
- expect(root).toContainNode(c);
210
- expect(root).toContainNode(d);
211
- });
212
-
213
- test("100 node random tree optimization does not degrade quality", () => {
214
- const random = seededRandom(42);
215
-
216
- const nodes = [];
217
-
218
- for (let i = 0; i < 100; i++) {
219
- const x0 = random() * 100;
220
- const y0 = random() * 100;
221
- const z0 = random() * 100;
222
-
223
- const x1 = x0 + random() * 5;
224
- const y1 = y0 + random() * 5;
225
- const z1 = z0 + random() * 5;
226
-
227
- nodes.push(new LeafNode(i, x0, y0, z0, x1, y1, z1));
228
- }
229
-
230
- while (nodes.length >= 2) {
231
- const left = nodes.pop();
232
- const right = nodes.pop();
233
- nodes.unshift(pair(left, right));
234
- }
235
-
236
- const root = nodes[0];
237
-
238
- const oldSAH = root.computeSAH();
239
-
240
- optimize(root, 100);
241
-
242
- expect(root).toBeValid();
243
-
244
- const newSAH = root.computeSAH();
245
-
246
- //at least not degraded
247
- expect(newSAH).toBeLessThanOrEqual(oldSAH);
248
- });
249
-
250
- test("case 0: 4 node tree optimization does not degrade quality", () => {
251
- const ll = new LeafNode("ll",
252
- 76.06244471671744,
253
- 7.73902752171125,
254
- 1.925105413576489,
255
- 94.49883157197291,
256
- 50.63123012084361,
257
- 76.75841101302467
258
- );
259
-
260
- const lr = new LeafNode("lr",
261
- 76.11310176957886,
262
- 58.65097077867176,
263
- 11.346076624795387,
264
- 97.55653706044541,
265
- 89.91247777413719,
266
- 90.73181902923352
267
- );
268
-
269
- const rl = new LeafNode("rl",
270
- 32.4771196630536,
271
- 0.9366270797727339,
272
- 1.378434756588831,
273
- 66.71670340545461,
274
- 99.32784918828929,
275
- 97.52435446605432
276
- );
277
-
278
- const rr = new LeafNode("rr",
279
- 1.124263022938976,
280
- 0.13232239543867763,
281
- 2.702786005283997,
282
- 31.51776058888572,
283
- 94.87720282424561,
284
- 101.03932220629758
285
- );
286
-
287
- const root = pair(pair(ll, lr), pair(rl, rr));
288
-
289
- expect(root).toBeValid();
290
-
291
- const oldSAH = root.computeSAH();
292
-
293
- optimize(root, 1000);
294
-
295
- expect(root).toBeValid();
296
-
297
- const newSAH = root.computeSAH();
298
-
299
- //at least not degraded
300
- expect(newSAH).toBeLessThanOrEqual(oldSAH);
301
- });
302
-
303
- })
@@ -1,260 +0,0 @@
1
- import { surfaceAreaHeuristic as sah } from "../sah/surfaceAreaHeuristic.js";
2
- import { isLeaf } from "../LeafNode.js";
3
- import { aabb3_score_boxes_SAH as computeAreaFor2 } from "../../geom/3d/aabb/aabb3_score_boxes_SAH.js";
4
- import { aabb3_box_surface_area_2 as computeArea } from "../../geom/3d/aabb/aabb3_box_surface_area_2.js";
5
-
6
- /**
7
- *
8
- * @param {Node} node
9
- * @param {BinaryNode} parent
10
- */
11
- function setParent(node, parent) {
12
- node.parentNode = parent;
13
- }
14
-
15
- /**
16
- * Based on paper "Fast, Effective BVH Updates for Animated Scenes" Kopta et. al. (url: http://www.cs.utah.edu/~thiago/papers/rotations.pdf)
17
- * @param {BinaryNode} node
18
- * @returns {int} value from 0 to 6, 0 means no rotation has taken place
19
- */
20
- export function tryRotateSingleNode(node) {
21
-
22
- const left = node.left;
23
- const right = node.right;
24
-
25
- if (left === null || right === null) {
26
- return 0;
27
- }
28
-
29
- /*
30
- First we compute best rotation to apply, enumerated by 0-6
31
- */
32
-
33
- let bestRotation = 0;
34
-
35
-
36
- const nodeArea = computeArea(node);
37
- const leftArea = computeArea(left);
38
- const rightArea = computeArea(right);
39
-
40
- const leftLeaves = left.leafNodeCount;
41
- const rightLeaves = right.leafNodeCount;
42
-
43
-
44
- let bestCost = sah(
45
- nodeArea,
46
- leftArea,
47
- rightArea,
48
- leftLeaves,
49
- rightLeaves
50
- );
51
-
52
- let candidateCost;
53
-
54
- let leftLeftArea,
55
- leftRightArea,
56
- rightLeftArea,
57
- rightRightArea;
58
-
59
- let leftLeft,
60
- leftRight,
61
- rightLeft,
62
- rightRight;
63
-
64
- let leftLeftLeaves,
65
- leftRightLeaves,
66
- rightLeftLeaves,
67
- rightRightLeaves;
68
-
69
- let considerLeft = !isLeaf(left);
70
-
71
- if (considerLeft) {
72
- leftLeft = left.left;
73
- leftRight = left.right;
74
-
75
- considerLeft = (leftLeft !== null && leftRight !== null);
76
- if (considerLeft) {
77
-
78
- leftLeftArea = computeArea(leftLeft);
79
- leftRightArea = computeArea(leftRight);
80
-
81
- leftLeftLeaves = leftLeft.leafNodeCount;
82
- leftRightLeaves = leftRight.leafNodeCount;
83
-
84
- // (1) N N //
85
- // / \ / \ //
86
- // L R -----> L LL //
87
- // / \ / \ //
88
- // LL LR R LR //
89
- candidateCost = sah(nodeArea, computeAreaFor2(right, leftRight), leftLeftArea, rightLeaves + leftRightLeaves, leftLeftLeaves);
90
-
91
- if (candidateCost < bestCost) {
92
- bestRotation = 1;
93
- bestCost = candidateCost;
94
- }
95
-
96
- // (2) N N //
97
- // / \ / \ //
98
- // L R -----> L LR //
99
- // / \ / \ //
100
- // LL LR LL R //
101
- candidateCost = sah(nodeArea, computeAreaFor2(leftLeft, right), leftRightArea, leftLeftLeaves + rightLeaves, leftRightLeaves);
102
-
103
-
104
- if (candidateCost < bestCost) {
105
- bestRotation = 2;
106
- bestCost = candidateCost;
107
- }
108
- }
109
- }
110
- if (!isLeaf(right)) {
111
- rightLeft = right.left;
112
- rightRight = right.right;
113
- if (rightLeft !== null && rightRight !== null) {
114
-
115
- rightLeftArea = computeArea(rightLeft);
116
- rightRightArea = computeArea(rightRight);
117
-
118
- rightLeftLeaves = rightLeft.leafNodeCount;
119
- rightRightLeaves = rightRight.leafNodeCount;
120
-
121
- // (3) N N //
122
- // / \ / \ //
123
- // L R -----> RL R //
124
- // / \ / \ //
125
- // RL RR L RR //
126
- candidateCost = sah(nodeArea, rightLeftArea, computeAreaFor2(left, rightRight), rightLeftLeaves, leftLeaves + rightRightLeaves);
127
-
128
- if (candidateCost < bestCost) {
129
- bestRotation = 3;
130
- bestCost = candidateCost;
131
- }
132
-
133
- // (4) N N //
134
- // / \ / \ //
135
- // L R -----> RR R //
136
- // / \ / \ //
137
- // RL RR RL L //
138
- candidateCost = sah(nodeArea, rightRightArea, computeAreaFor2(rightLeft, left), rightRightLeaves, rightLeftLeaves + leftLeaves);
139
-
140
-
141
- if (candidateCost < bestCost) {
142
- bestRotation = 4;
143
- bestCost = candidateCost;
144
- }
145
-
146
- if (considerLeft) {
147
- //both child nodes are not leaf
148
-
149
- // (5) N N //
150
- // / \ / \ //
151
- // L R -----> L R //
152
- // / \ / \ / \ / \ //
153
- // LL LR RL RR LL RL LR RR //
154
- candidateCost = sah(
155
- nodeArea,
156
- computeAreaFor2(leftLeft, rightLeft),
157
- computeAreaFor2(leftRight, rightRight),
158
- leftLeftLeaves + rightLeftLeaves,
159
- leftRightLeaves + rightRightLeaves
160
- );
161
-
162
-
163
- if (candidateCost < bestCost) {
164
- bestRotation = 5;
165
- bestCost = candidateCost;
166
- }
167
-
168
- // (6) N N //
169
- // / \ / \ //
170
- // L R -----> L R //
171
- // / \ / \ / \ / \ //
172
- // LL LR RL RR LL RR RL LR //
173
- candidateCost = sah(
174
- nodeArea,
175
- computeAreaFor2(leftLeft, rightRight),
176
- computeAreaFor2(rightLeft, leftRight),
177
- leftLeftLeaves + rightRightLeaves,
178
- rightLeftLeaves + leftRightLeaves
179
- );
180
-
181
- if (candidateCost < bestCost) {
182
- bestRotation = 6;
183
- }
184
- }
185
- }
186
- }
187
-
188
- switch (bestRotation) {
189
- case 0:
190
- //no rotation
191
- break;
192
- case 1:
193
- node.right = leftLeft;
194
- setParent(leftLeft, node);
195
- left.left = right;
196
- setParent(right, left);
197
-
198
- left.refit();
199
- //update leaf count
200
- node.left.updateLeafNodeCount();
201
- break;
202
- case 2:
203
- node.right = leftRight;
204
- setParent(leftRight, node);
205
- left.right = right;
206
- setParent(right, left);
207
-
208
- left.refit();
209
- //update leaf count
210
- node.left.updateLeafNodeCount();
211
- break;
212
- case 3:
213
- node.left = rightLeft;
214
- setParent(rightLeft, node);
215
- right.left = left;
216
- setParent(left, right);
217
-
218
- right.refit();
219
- //update leaf count
220
- node.right.updateLeafNodeCount();
221
- break;
222
- case 4:
223
- node.left = rightRight;
224
- setParent(rightRight, node);
225
- right.right = left;
226
- setParent(left, right);
227
-
228
- right.refit();
229
- //update leaf count
230
- node.right.updateLeafNodeCount();
231
- break;
232
- case 5:
233
- left.right = rightLeft;
234
- setParent(rightLeft, left);
235
- right.left = leftRight;
236
- setParent(leftRight, right);
237
-
238
- left.refit();
239
- right.refit();
240
-
241
- //update leaf count
242
- node.left.updateLeafNodeCount();
243
- node.right.updateLeafNodeCount();
244
- break;
245
- case 6:
246
- left.right = rightRight;
247
- setParent(rightRight, left);
248
- right.right = leftRight;
249
- setParent(leftRight, right);
250
-
251
- left.refit();
252
- right.refit();
253
- //update leaf count
254
- node.left.updateLeafNodeCount();
255
- node.right.updateLeafNodeCount();
256
- break;
257
- }
258
-
259
- return bestRotation;
260
- }
@@ -1,30 +0,0 @@
1
- export class BVHVisitor {
2
- constructor() {
3
-
4
- }
5
-
6
- initialize() {
7
-
8
- }
9
-
10
- finalize() {
11
-
12
- }
13
-
14
- /**
15
- *
16
- * @param {LeafNode} node
17
- */
18
- visitLeaf(node) {
19
-
20
- }
21
-
22
- /**
23
- *
24
- * @param {BinaryNode} node
25
- * @returns {boolean} true if traversal should go deeper, false to exclude descendants from traversal
26
- */
27
- visitBinary(node) {
28
- return true;
29
- }
30
- }
@@ -1,66 +0,0 @@
1
- import { BVHVisitor } from "./BVHVisitor.js";
2
-
3
- export class RaycastBVHVisitor extends BVHVisitor {
4
- constructor() {
5
- super();
6
-
7
- this.originX = 0;
8
- this.originY = 0;
9
- this.originZ = 0;
10
-
11
- this.directionX = 0;
12
- this.directionY = 0;
13
- this.directionZ = 0;
14
-
15
- /**
16
- *
17
- * @type {BVHVisitor}
18
- */
19
- this.collector = null;
20
- }
21
-
22
- /**
23
- *
24
- * @param {number} x
25
- * @param {number} y
26
- * @param {number} z
27
- */
28
- setOrigin(x, y, z) {
29
- this.originX = x;
30
- this.originY = y;
31
- this.originZ = z;
32
- }
33
-
34
- /**
35
- *
36
- * @param {number} x
37
- * @param {number} y
38
- * @param {number} z
39
- */
40
- setDirection(x, y, z) {
41
- this.directionX = x;
42
- this.directionY = y;
43
- this.directionZ = z;
44
- }
45
-
46
- visitLeaf(node) {
47
-
48
- const b = node.intersectRay(this.originX, this.originY, this.originZ, this.directionX, this.directionY, this.directionZ);
49
-
50
-
51
- if (b) {
52
- this.collector.visitLeaf(node);
53
- }
54
-
55
- }
56
-
57
- visitBinary(node) {
58
- const b = node.intersectRay(this.originX, this.originY, this.originZ, this.directionX, this.directionY, this.directionZ);
59
-
60
- if (b) {
61
- this.collector.visitBinary(node);
62
- }
63
-
64
- return b;
65
- }
66
- }