@woosh/meep-engine 2.67.0 → 2.68.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 (50) hide show
  1. package/build/meep.cjs +0 -1
  2. package/build/meep.module.js +0 -1
  3. package/package.json +1 -1
  4. package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -1
  5. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +0 -5
  6. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +0 -1
  7. package/src/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +16 -19
  8. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +46 -47
  9. package/src/core/bvh2/BVHTasks.js +0 -65
  10. package/src/core/bvh2/BinaryNode.d.ts +0 -13
  11. package/src/core/bvh2/BinaryNode.js +0 -1188
  12. package/src/core/bvh2/BinaryNode.spec.js +0 -309
  13. package/src/core/bvh2/LeafNode.d.ts +0 -7
  14. package/src/core/bvh2/LeafNode.js +0 -147
  15. package/src/core/bvh2/Node.d.ts +0 -9
  16. package/src/core/bvh2/Node.js +0 -196
  17. package/src/core/bvh2/NodeValidator.js +0 -197
  18. package/src/core/bvh2/StacklessTraverser.js +0 -154
  19. package/src/core/bvh2/StacklessTraverser.spec.js +0 -109
  20. package/src/core/bvh2/serialization/deserializeBinaryNode.js +0 -40
  21. package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +0 -90
  22. package/src/core/bvh2/serialization/serializeBinaryNode.js +0 -31
  23. package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +0 -86
  24. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +0 -144
  25. package/src/core/bvh2/transform/RotationOptimizer.js +0 -123
  26. package/src/core/bvh2/transform/RotationOptimizer.spec.js +0 -303
  27. package/src/core/bvh2/transform/tryRotateSingleNode.js +0 -260
  28. package/src/core/bvh2/traversal/BVHVisitor.js +0 -30
  29. package/src/core/bvh2/traversal/RaycastBVHVisitor.js +0 -66
  30. package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +0 -384
  31. package/src/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +0 -52
  32. package/src/core/bvh2/traversal/bvh_traverse_pre_order_using_stack.js +0 -43
  33. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.d.ts +0 -5
  34. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.js +0 -66
  35. package/src/core/bvh2/traversal/queryBinaryNode_CollectData.js +0 -49
  36. package/src/core/bvh2/traversal/queryBinaryNode_CollectLeaves.js +0 -51
  37. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +0 -77
  38. package/src/core/bvh2/traversal/queryBinaryNode_SphereIntersections.js +0 -63
  39. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +0 -50
  40. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder.js +0 -34
  41. package/src/core/bvh2/util/find_least_common_ancestor.js +0 -34
  42. package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +0 -50
  43. package/src/core/geom/2d/bvh/BinaryNode2.js +0 -152
  44. package/src/core/geom/2d/bvh/LeafNode2.js +0 -11
  45. package/src/core/geom/2d/bvh/Node2.js +0 -51
  46. package/src/engine/ecs/terrain/tiles/FirstRayIntersectionTerrainBVHVisitor.js +0 -74
  47. package/src/engine/graphics/geometry/bvh/BVHFromGeometry.js +0 -72
  48. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +0 -240
  49. package/src/engine/graphics/geometry/bvh/buffered/IndexedTraingleBoundsComputer.js +0 -43
  50. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +0 -133
@@ -1,309 +0,0 @@
1
- import { BinaryBuffer } from "../binary/BinaryBuffer.js";
2
- import { BinaryNode } from "./BinaryNode.js";
3
- import { isLeaf, LeafNode } from "./LeafNode.js";
4
- import { validateNode, validateTree } from "./NodeValidator.js";
5
- import { deserializeBinaryNode } from "./serialization/deserializeBinaryNode.js";
6
- import { deserializeBinaryNodeFromBinaryBuffer } from "./serialization/deserializeBinaryNodeFromBinaryBuffer.js";
7
- import { serializeBinaryNode } from "./serialization/serializeBinaryNode.js";
8
- import { serializeBinaryNodeToBinaryBuffer } from "./serialization/serializeBinaryNodeToBinaryBuffer.js";
9
- import {byteArrayToString} from "../binary/byteArrayToString.js";
10
- import {jsonToStringToByteArray} from "../binary/jsonToStringToByteArray.js";
11
-
12
- /**
13
- *
14
- * @param {AABB3} expected
15
- * @param {AABB3} actual
16
- * @param {number} [numDigits]
17
- */
18
- function compareBounds(expected, actual, numDigits = 2) {
19
- expect(actual.x0).toBeCloseTo(expected.x0, numDigits);
20
- expect(actual.y0).toBeCloseTo(expected.y0, numDigits);
21
- expect(actual.z0).toBeCloseTo(expected.z0, numDigits);
22
- expect(actual.x1).toBeCloseTo(expected.x1, numDigits);
23
- expect(actual.y1).toBeCloseTo(expected.y1, numDigits);
24
- expect(actual.z1).toBeCloseTo(expected.z1, numDigits);
25
- }
26
-
27
- /**
28
- *
29
- * @param {NodeDescription} expected
30
- * @param {NodeDescription} actual
31
- */
32
- function compareNodes(expected, actual) {
33
- if (expected === undefined) {
34
- expect(actual).toBeUndefined();
35
- }
36
- if (expected === null) {
37
- expect(actual).toBeNull();
38
- }
39
-
40
- if (expected instanceof BinaryNode) {
41
- expect(actual instanceof BinaryNode).toBeTruthy();
42
- compareBounds(expected, actual);
43
-
44
- compareNodes(expected.left, actual.left);
45
- compareNodes(expected.right, actual.right);
46
- } else if (expected instanceof LeafNode) {
47
- expect(actual instanceof LeafNode).toBeTruthy();
48
- compareBounds(expected, actual);
49
- expect(actual.object).toEqual(expected.object);
50
- }
51
- }
52
-
53
- expect.extend({
54
- toBeValid(node) {
55
- const violations = [];
56
-
57
- function violationCallback(v) {
58
- violations.push(v);
59
- }
60
-
61
- let pass = true;
62
- if (isLeaf(node)) {
63
- pass = pass && validateNode(node, violationCallback);
64
- } else {
65
- pass = pass && validateTree(node, violationCallback);
66
- }
67
-
68
- if (!pass) {
69
- let message = violations.map((v) => v.toString()).join("\n");
70
-
71
- if (message.trim().length === 0) {
72
- message = `node is not valid`;
73
- }
74
-
75
- return {
76
- message: function () {
77
- return message
78
- },
79
- pass: false
80
- };
81
- }
82
-
83
- return {
84
- pass: true
85
- };
86
- },
87
- /**
88
- *
89
- * @param {BinaryNode} container
90
- * @param node
91
- */
92
- toContainNode(container, node) {
93
- let found = false;
94
- let message;
95
- container.traversePreOrderUsingStack(function (n) {
96
- if (n === node) {
97
- found = true;
98
- //stop traversal
99
- return false;
100
- }
101
- });
102
-
103
- if (!found) {
104
- message = `node is not contained within the tree`;
105
- }
106
-
107
- return {
108
- message,
109
- pass: found
110
- };
111
- }
112
- });
113
-
114
- test("constructor", () => {
115
- const node = new BinaryNode();
116
-
117
- expect(node.left).toBeNull();
118
- expect(node.right).toBeNull();
119
- expect(node.parentNode).toBeNull();
120
- });
121
-
122
- test("insert single leaf", () => {
123
- const binaryNode = new BinaryNode();
124
- binaryNode.setNegativelyInfiniteBounds();
125
-
126
- const leafNode = new LeafNode(7, 1, 2, 3, 4, 5, 6);
127
-
128
- binaryNode.insertNode(leafNode);
129
-
130
- expect(binaryNode).toBeValid();
131
- expect(leafNode).toBeValid();
132
-
133
- expect(binaryNode).toContainNode(leafNode);
134
- expect(leafNode.parentNode).toBe(binaryNode);
135
- });
136
-
137
- test("insert many leaves", () => {
138
- const binaryNode = new BinaryNode();
139
- binaryNode.setNegativelyInfiniteBounds();
140
-
141
- const leaves = [];
142
-
143
- for (let i = 0; i < 17; i++) {
144
- const leafNode = new LeafNode(i, i, i, i, i + 1, i + 1, i + 1);
145
- binaryNode.insertNode(leafNode);
146
-
147
- leaves.push(leafNode);
148
- }
149
-
150
- expect(binaryNode).toBeValid();
151
-
152
- for (let i = 0; i < leaves.length; i++) {
153
- const leaf = leaves[i];
154
-
155
- expect(leaf.computeRoot()).toBe(binaryNode);
156
-
157
- expect(binaryNode).toContainNode(leaf);
158
- }
159
- });
160
-
161
- test("disconnect single leaf", () => {
162
- const binaryNode = new BinaryNode();
163
- binaryNode.setNegativelyInfiniteBounds();
164
-
165
- const leafNode = new LeafNode(7, 1, 2, 3, 4, 5, 6);
166
-
167
- binaryNode.insertNode(leafNode);
168
-
169
- expect(binaryNode).toContainNode(leafNode);
170
-
171
- leafNode.disconnect();
172
-
173
- expect(leafNode.parentNode).toBeNull();
174
-
175
- expect(binaryNode).not.toContainNode(leafNode);
176
-
177
- expect(binaryNode).toBeValid();
178
- });
179
-
180
- test("disconnect many leaves", () => {
181
- const binaryNode = new BinaryNode();
182
- binaryNode.setNegativelyInfiniteBounds();
183
-
184
- const leaves = [];
185
-
186
- for (let i = 0; i < 17; i++) {
187
- const leafNode = new LeafNode(i, i, i, i, i + 1, i + 1, i + 1);
188
- binaryNode.insertNode(leafNode);
189
-
190
- leaves.push(leafNode);
191
- }
192
-
193
- expect(binaryNode).toBeValid();
194
-
195
- for (let i = 0; i < leaves.length; i++) {
196
- const leaf = leaves[i];
197
- leaf.disconnect();
198
-
199
- expect(leaf.parentNode).toBeNull();
200
-
201
- expect(binaryNode).not.toContainNode(leaf);
202
-
203
- expect(binaryNode).toBeValid();
204
- }
205
- });
206
-
207
- test("serialization deserialization consistency", () => {
208
- const expected = new BinaryNode();
209
-
210
- expected.setNegativelyInfiniteBounds();
211
-
212
- expected.insert(1, 2, 3, 4, 5, 6, "hello");
213
- expected.insert(7, 8, 9, 10, 11, 12, "goodbye");
214
- expected.insert(-6, -5, -4, -3, -2, -1, "world is cruel");
215
-
216
- const buffer = new BinaryBuffer();
217
-
218
- serializeBinaryNode(buffer, expected, function (buffer, value) {
219
- const byteArray = new Uint8Array(jsonToStringToByteArray(value));
220
- const numBytes = byteArray.length;
221
- buffer.writeUint32(numBytes);
222
- buffer.writeBytes(byteArray, 0, numBytes);
223
- });
224
-
225
- //reset position for reading
226
- buffer.position = 0;
227
-
228
- //
229
- const actual = new BinaryNode();
230
-
231
- deserializeBinaryNode(buffer, actual, function (buffer) {
232
- const numBytes = buffer.readUint32();
233
- const uint8Array = new Uint8Array(numBytes);
234
- buffer.readBytes(uint8Array, 0, numBytes);
235
-
236
- const text = byteArrayToString(uint8Array);
237
- return JSON.parse(text);
238
- });
239
-
240
-
241
- compareNodes(expected, actual);
242
- });
243
-
244
- test("serialization deserialization consistency via to/fromBinaryBuffer", () => {
245
- const expected = new BinaryNode();
246
-
247
- expected.setNegativelyInfiniteBounds();
248
-
249
- expected.insert(1, 2, 3, 4, 5, 6, "hello");
250
- expected.insert(7, 8, 9, 10, 11, 12, "goodbye");
251
- expected.insert(-6, -5, -4, -3, -2, -1, "world is cruel");
252
-
253
- const buffer = new BinaryBuffer();
254
-
255
- serializeBinaryNodeToBinaryBuffer(expected, buffer, function (buffer, value) {
256
- const byteArray = new Uint8Array(jsonToStringToByteArray(value));
257
- const numBytes = byteArray.length;
258
- buffer.writeUint32(numBytes);
259
- buffer.writeBytes(byteArray, 0, numBytes);
260
- });
261
-
262
- //reset position for reading
263
- buffer.position = 0;
264
-
265
- //
266
- const actual = new BinaryNode();
267
-
268
- deserializeBinaryNodeFromBinaryBuffer(actual, buffer, function (buffer) {
269
- const numBytes = buffer.readUint32();
270
- const uint8Array = new Uint8Array(numBytes);
271
- buffer.readBytes(uint8Array, 0, numBytes);
272
-
273
- const text = byteArrayToString(uint8Array);
274
- return JSON.parse(text);
275
- });
276
-
277
-
278
- compareNodes(expected, actual);
279
- });
280
-
281
- test("setChildren", () => {
282
- const root = new BinaryNode();
283
-
284
- const a = new BinaryNode();
285
- a.setBounds(0, 1, 2, 1, 1, 3);
286
-
287
- const b = new BinaryNode();
288
- b.setBounds(-1, -2, -3, 0, 2, 2);
289
-
290
- root.setChildren(a, b);
291
- root.refit();
292
-
293
- expect(a.parentNode).toBe(root);
294
- expect(b.parentNode).toBe(root);
295
-
296
- expect(root.left).toBe(a);
297
- expect(root.right).toBe(b);
298
-
299
- //check refitting
300
- expect(root.x0).toBe(-1);
301
- expect(root.y0).toBe(-2);
302
- expect(root.z0).toBe(-3);
303
- expect(root.x1).toBe(1);
304
- expect(root.y1).toBe(2);
305
- expect(root.z1).toBe(3);
306
-
307
- expect(root).toBeValid();
308
- });
309
-
@@ -1,7 +0,0 @@
1
- import {Node} from "./Node";
2
-
3
- export class LeafNode<T> extends Node<T> {
4
- object: T
5
-
6
- constructor(object: T, x0: number, y0: number, z0: number, x1: number, y1: number, z1: number)
7
- }
@@ -1,147 +0,0 @@
1
- /**
2
- * Created by Alex on 17/11/2014.
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";
7
-
8
-
9
- /**
10
- *
11
- * @param {Node|LeafNode} node
12
- * @returns {boolean}
13
- */
14
- function isLeaf(node) {
15
- return node.isLeafNode;
16
- }
17
-
18
- /**
19
- * @deprecated use {@link BVH} and {@link BvhClient} respectively
20
- */
21
- export class LeafNode extends Node {
22
- /**
23
- *
24
- * @param {*} object
25
- * @param {number} x0
26
- * @param {number} y0
27
- * @param {number} z0
28
- * @param {number} x1
29
- * @param {number} y1
30
- * @param {number} z1
31
- * @constructor
32
- */
33
- constructor(object, x0, y0, z0, x1, y1, z1) {
34
- super();
35
-
36
- this.object = object;
37
- this.parentNode = null;
38
-
39
- this.x0 = x0;
40
- this.y0 = y0;
41
- this.z0 = z0;
42
- this.x1 = x1;
43
- this.y1 = y1;
44
- this.z1 = z1;
45
-
46
- }
47
-
48
- /**
49
- *
50
- * @param {number} dx
51
- * @param {number} dy
52
- * @param {number} dz
53
- */
54
- move(dx, dy, dz) {
55
- this.x0 += dx;
56
- this.x1 += dx;
57
- this.y0 += dy;
58
- this.y1 += dy;
59
- this.z0 += dz;
60
- this.z1 += dz;
61
- if (this.parentNode !== null) {
62
- this.parentNode.bubbleRefit();
63
- }
64
- }
65
-
66
- /**
67
- *
68
- * @param {number} x0
69
- * @param {number} y0
70
- * @param {number} z0
71
- * @param {number} x1
72
- * @param {number} y1
73
- * @param {number} z1
74
- */
75
- resize(x0, y0, z0, x1, y1, z1) {
76
- this.setBounds(x0, y0, z0, x1, y1, z1);
77
-
78
- this.bubbleRefit();
79
- }
80
-
81
- bubbleRefit() {
82
-
83
- if (this.parentNode !== null) {
84
- this.parentNode.bubbleRefit();
85
- }
86
- }
87
-
88
- /**
89
- *
90
- * @return {LeafNode}
91
- */
92
- clone() {
93
- const clone = new LeafNode(this.object, this.x0, this.y0, this.z0, this.x1, this.y1, this.z1);
94
-
95
- clone.parentNode = this.parentNode;
96
-
97
- return clone;
98
- }
99
- }
100
-
101
- /**
102
- *
103
- * @type {boolean}
104
- */
105
- LeafNode.prototype.isLeafNode = true;
106
-
107
- /**
108
- * Leaf node will have height 0, root node will have height equal to maximum depth of the tree
109
- * @type {number}
110
- */
111
- LeafNode.prototype.height = 0;
112
-
113
- /**
114
- * Useful shortcut, to avoid having to distinguish between leaf and intermediate nodes
115
- * @readonly
116
- * @deprecated
117
- * @type {number}
118
- */
119
- LeafNode.prototype.leafNodeCount = 1;
120
-
121
- /**
122
- *
123
- * @param {BinaryBuffer} buffer
124
- * @param {LeafNode} node
125
- * @param {function(buffer:BinaryBuffer, value:*):void} valueSerializer
126
- */
127
- function serializeLeafNode(buffer, node, valueSerializer) {
128
- serializeAABB3(buffer, node);
129
- valueSerializer(buffer, node.object);
130
- }
131
-
132
- /**
133
- *
134
- * @param {BinaryBuffer} buffer
135
- * @param {LeafNode} node
136
- * @param {function(buffer:BinaryBuffer):void} valueDeserializer
137
- */
138
- function deserializeLeafNode(buffer, node, valueDeserializer) {
139
- deserializeAABB3(buffer, node);
140
- node.object = valueDeserializer(buffer);
141
- }
142
-
143
- export {
144
- isLeaf,
145
- serializeLeafNode,
146
- deserializeLeafNode
147
- };
@@ -1,9 +0,0 @@
1
- import {AABB3} from "../geom/3d/aabb/AABB3";
2
- import {BinaryNode} from "./BinaryNode";
3
-
4
- export class Node<T> extends AABB3 {
5
- public parentNode: BinaryNode<T>
6
-
7
-
8
- readonly leafNodeCount: number
9
- }
@@ -1,196 +0,0 @@
1
- /**
2
- * Created by Alex on 17/11/2014.
3
- */
4
- import computeMortonCode from "../geom/3d/morton/Morton.js";
5
- import { AABB3 } from "../geom/3d/aabb/AABB3.js";
6
-
7
-
8
- export class Node extends AABB3 {
9
- constructor() {
10
- super();
11
-
12
- /**
13
- *
14
- * @type {BinaryNode|null}
15
- */
16
- this.parentNode = null;
17
- this._mortonCode = void 0;
18
- }
19
-
20
- /**
21
- * @return {boolean}
22
- */
23
- validateAncestorChain() {
24
- //check containment
25
- const parent = this.parentNode;
26
- if (parent === null) {
27
- //nothing to do
28
- return true;
29
- }
30
-
31
- if (!parent.containsBox(this)) {
32
- //bounds violated
33
- return false;
34
- }
35
-
36
- if (parent.left === this || parent.right === this) {
37
- //all is well
38
- } else {
39
- return false;
40
- }
41
-
42
- return true;
43
- }
44
-
45
- /**
46
- *
47
- * @returns {number}
48
- */
49
- computeDepth() {
50
- let d = 0;
51
- let node = this.parentNode;
52
-
53
- while (node !== null) {
54
- node = node.parentNode;
55
-
56
- d++;
57
- }
58
-
59
- return d;
60
- }
61
-
62
- /**
63
- *
64
- * @returns {Node}
65
- */
66
- computeRoot() {
67
- let p = this;
68
-
69
- while (p.parentNode !== null) {
70
- p = p.parentNode;
71
- }
72
-
73
- return p;
74
- }
75
-
76
- getMortonCode() {
77
- if (this._mortonCode === void 0) {
78
- const hx = (this.x1 + this.x0) / 2;
79
- const hy = (this.y1 + this.y0) / 2;
80
- const hz = (this.z1 + this.z0) / 2;
81
- const mortonCode = computeMortonCode(hx, hy, hz);
82
- this._mortonCode = mortonCode;
83
- return mortonCode;
84
- } else {
85
- return this._mortonCode;
86
- }
87
- }
88
-
89
- /**
90
- * Expands current node and all ancestors until root to accommodate for given box, terminate if node is already
91
- * large enough
92
- * @param {AABB3} box
93
- */
94
- bubbleExpandToFit(box) {
95
- let node = this;
96
- while (node.expandToFit(box)) {
97
- node = node.parentNode;
98
- if (node === null) {
99
- break;
100
- }
101
- }
102
- }
103
-
104
- /**
105
- * @deprecated
106
- */
107
- remove() {
108
- console.error("This method is deprecated, use 'disconnect' instead.");
109
- this.disconnect();
110
- }
111
-
112
- /**
113
- * Detaches this node from its parent
114
- */
115
- disconnect() {
116
- const node = this.parentNode;
117
-
118
- if (node === null) {
119
- //no parent already
120
- // console.warn(`Node has no parent, nothing to disconnect from`);
121
- return;
122
- }
123
-
124
- if (this === node.left) {
125
- node.left = null;
126
- this.parentNode = null;
127
- } else if (this === node.right) {
128
- node.right = null;
129
- this.parentNode = null;
130
- } else {
131
- throw new Error("impostor child");
132
- }
133
-
134
- node.updateLeafNodeCount();
135
- node.updateHeight();
136
- }
137
-
138
- /**
139
- * traverses all siblings up to the root
140
- */
141
- traverseSiblingsUp() {
142
- throw new Error('Not Implemented');
143
- }
144
- }
145
-
146
- function buildPathForNode(n) {
147
-
148
- const chain = [];
149
-
150
- let node = n;
151
- while (node !== null) {
152
-
153
- const parentNode = node.parentNode;
154
-
155
- if (parentNode === null) {
156
- break;
157
- }
158
-
159
- if (parentNode.left === node) {
160
- chain.unshift('left');
161
- } else {
162
- chain.unshift('right');
163
- }
164
-
165
- node = parentNode;
166
- }
167
-
168
- return chain;
169
- }
170
-
171
- /**
172
- *
173
- * @param {string[]} path
174
- * @returns {string}
175
- */
176
- function strinfityPath(path) {
177
- return '/' + path.join('/');
178
- }
179
-
180
-
181
- /**
182
- *
183
- * @param {Node} n
184
- * @param {int} len maximum number of path elements
185
- * @returns {string}
186
- */
187
- export function buildShortStringPath(n, len) {
188
- const longPath = buildPathForNode(n);
189
-
190
- if (longPath.length > len) {
191
- return '...' + strinfityPath(longPath.splice(-len));
192
- } else {
193
- return strinfityPath(longPath);
194
- }
195
- }
196
-