@woosh/meep-engine 2.66.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 (58) hide show
  1. package/build/meep.cjs +127 -1756
  2. package/build/meep.min.js +1 -1
  3. package/build/meep.module.js +127 -1756
  4. package/package.json +1 -1
  5. package/src/engine/graphics/GraphicsEngine.js +16 -25
  6. package/src/engine/graphics/camera/testClippingPlaneComputation.js +5 -5
  7. package/src/engine/graphics/ecs/compileAllMaterials.js +5 -12
  8. package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -1
  9. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +0 -5
  10. package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +0 -1
  11. package/src/engine/graphics/ecs/mesh-v2/sample/prototypeShadedGeometry.js +22 -24
  12. package/src/engine/graphics/ecs/mesh-v2/sample/prototype_sg_raycast.js +21 -23
  13. package/src/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +16 -19
  14. package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +46 -47
  15. package/src/engine/graphics/render/layers/RenderLayer.d.ts +0 -5
  16. package/src/engine/graphics/render/layers/RenderLayer.js +29 -45
  17. package/src/core/bvh2/BVHTasks.js +0 -65
  18. package/src/core/bvh2/BinaryNode.d.ts +0 -13
  19. package/src/core/bvh2/BinaryNode.js +0 -1188
  20. package/src/core/bvh2/BinaryNode.spec.js +0 -309
  21. package/src/core/bvh2/LeafNode.d.ts +0 -7
  22. package/src/core/bvh2/LeafNode.js +0 -147
  23. package/src/core/bvh2/Node.d.ts +0 -9
  24. package/src/core/bvh2/Node.js +0 -196
  25. package/src/core/bvh2/NodeValidator.js +0 -197
  26. package/src/core/bvh2/StacklessTraverser.js +0 -154
  27. package/src/core/bvh2/StacklessTraverser.spec.js +0 -109
  28. package/src/core/bvh2/serialization/deserializeBinaryNode.js +0 -40
  29. package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +0 -90
  30. package/src/core/bvh2/serialization/serializeBinaryNode.js +0 -31
  31. package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +0 -86
  32. package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +0 -144
  33. package/src/core/bvh2/transform/RotationOptimizer.js +0 -123
  34. package/src/core/bvh2/transform/RotationOptimizer.spec.js +0 -303
  35. package/src/core/bvh2/transform/tryRotateSingleNode.js +0 -260
  36. package/src/core/bvh2/traversal/BVHVisitor.js +0 -30
  37. package/src/core/bvh2/traversal/RaycastBVHVisitor.js +0 -66
  38. package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +0 -384
  39. package/src/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +0 -52
  40. package/src/core/bvh2/traversal/bvh_traverse_pre_order_using_stack.js +0 -43
  41. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.d.ts +0 -5
  42. package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.js +0 -66
  43. package/src/core/bvh2/traversal/queryBinaryNode_CollectData.js +0 -49
  44. package/src/core/bvh2/traversal/queryBinaryNode_CollectLeaves.js +0 -51
  45. package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +0 -77
  46. package/src/core/bvh2/traversal/queryBinaryNode_SphereIntersections.js +0 -63
  47. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +0 -50
  48. package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder.js +0 -34
  49. package/src/core/bvh2/util/find_least_common_ancestor.js +0 -34
  50. package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +0 -50
  51. package/src/core/geom/2d/bvh/BinaryNode2.js +0 -152
  52. package/src/core/geom/2d/bvh/LeafNode2.js +0 -11
  53. package/src/core/geom/2d/bvh/Node2.js +0 -51
  54. package/src/engine/ecs/terrain/tiles/FirstRayIntersectionTerrainBVHVisitor.js +0 -74
  55. package/src/engine/graphics/geometry/bvh/BVHFromGeometry.js +0 -72
  56. package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +0 -240
  57. package/src/engine/graphics/geometry/bvh/buffered/IndexedTraingleBoundsComputer.js +0 -43
  58. package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_objects.js +0 -133
@@ -1,77 +0,0 @@
1
- import { aabb3_intersects_frustum_degree } from "../../geom/3d/aabb/aabb3_intersects_frustum_degree.js";
2
- import { queryBinaryNode_CollectData } from "./queryBinaryNode_CollectData.js";
3
-
4
- /**
5
- *
6
- * @type {(BinaryNode|LeafNode)[]}
7
- */
8
- const stack = [];
9
-
10
-
11
- /**
12
- * @template T
13
- * @param {T[]} destination
14
- * @param {number} destination_offset
15
- * @param {BinaryNode<T>} root
16
- * @param {ArrayLike<number>|number[]|Float32Array} frustum
17
- * @returns {number} Number of results
18
- */
19
- export function queryBinaryNode_FrustumIntersections_Data(destination, destination_offset, root, frustum) {
20
-
21
- /**
22
- * @type {BinaryNode<T>|LeafNode<T>}
23
- */
24
- let n;
25
- let offset = destination_offset;
26
- let stackPointer = 1;
27
-
28
- stack[0] = root;
29
-
30
- while (stackPointer > 0) {
31
-
32
- stackPointer--;
33
-
34
- n = stack[stackPointer];
35
-
36
- const intersection_degree = aabb3_intersects_frustum_degree(
37
- n.x0, n.y0, n.z0,
38
- n.x1, n.y1, n.z1,
39
- frustum
40
- );
41
-
42
- if (intersection_degree === 2) {
43
- // fully inside
44
-
45
- offset += queryBinaryNode_CollectData(destination, offset, n);
46
-
47
- } else if (intersection_degree === 1) {
48
- // partly inside
49
-
50
- if (n.isBinaryNode === true) {
51
-
52
- const right = n.right;
53
-
54
- if (right !== null) {
55
- stack[stackPointer++] = right;
56
- }
57
-
58
- const left = n.left;
59
-
60
- if (left !== null) {
61
- stack[stackPointer++] = left;
62
- }
63
-
64
- } else {
65
- // leaf node
66
-
67
- destination[offset] = n.object;
68
-
69
- offset++;
70
- }
71
-
72
- }
73
-
74
- }
75
-
76
- return offset - destination_offset;
77
- }
@@ -1,63 +0,0 @@
1
- /**
2
- *
3
- * @type {(BinaryNode|LeafNode)[]}
4
- */
5
- const stack = [];
6
- let stackPointer = 0;
7
-
8
-
9
- /**
10
- * @template T
11
- * @param {T[]} destination
12
- * @param {number} destinationOffset
13
- * @param {BinaryNode<T>} root
14
- * @param {number} x
15
- * @param {number} y
16
- * @param {number} z
17
- * @param {number} radius
18
- * @returns {number} Number of results
19
- */
20
- export function queryBinaryNode_SphereIntersections_Data(destination, destinationOffset, root, x, y, z, radius) {
21
- let n;
22
-
23
- const radius2 = radius * radius;
24
-
25
- const stackOffset = stackPointer;
26
-
27
- stack[stackPointer++] = root;
28
-
29
- let i = 0;
30
-
31
- while (stackPointer-- > stackOffset) {
32
-
33
- n = stack[stackPointer];
34
-
35
- const d2 = n.distanceToPoint2(x, y, z);
36
- if (d2 >= radius2) {
37
- continue;
38
- }
39
-
40
- if (n.isBinaryNode) {
41
-
42
- if (n.right !== null) {
43
- stack[stackPointer++] = n.right;
44
- }
45
-
46
- if (n.left !== null) {
47
- stack[stackPointer++] = n.left;
48
- }
49
-
50
- } else {
51
-
52
- destination[destinationOffset + i] = n.object;
53
-
54
- i++;
55
- }
56
-
57
- }
58
-
59
- //drop the stack frame
60
- stackPointer = stackOffset;
61
-
62
- return i;
63
- }
@@ -1,50 +0,0 @@
1
- const stack = [];
2
- let stackPointer = 0;
3
-
4
- /**
5
- *
6
- * @param {BinaryNode} node
7
- * @param {BVHVisitor} visitor
8
- */
9
- export function traverseBinaryNodeUsingVisitor(node, visitor) {
10
- let n;
11
-
12
- const stackOffset = stackPointer;
13
-
14
- stack[stackPointer++] = node;
15
-
16
- while (stackPointer-- > stackOffset) {
17
-
18
- n = stack[stackPointer];
19
-
20
- if (n.isBinaryNode) {
21
- const traverseDeeper = visitor.visitBinary(n);
22
-
23
- if (traverseDeeper !== false) {
24
-
25
- if (n.left !== null) {
26
-
27
- // has a LEFT child
28
-
29
- stack[stackPointer++] = n.left;
30
-
31
- }
32
-
33
- if (n.right !== null) {
34
-
35
- // has a RIGHT child
36
-
37
- stack[stackPointer++] = n.right;
38
-
39
- }
40
-
41
- }
42
- } else {
43
- visitor.visitLeaf(n);
44
- }
45
-
46
- }
47
-
48
- //drop the stack frame
49
- stackPointer = stackOffset;
50
- }
@@ -1,34 +0,0 @@
1
-
2
- /**
3
- *
4
- * @param {BinaryNode} node
5
- * @param {BVHVisitor} visitor
6
- */
7
- export function traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder(node, visitor) {
8
- if (node.isBinaryNode) {
9
- const traverseDeeper = visitor.visitBinary(node);
10
-
11
- if (traverseDeeper) {
12
-
13
- if (node.left !== null) {
14
-
15
- // has a LEFT child
16
-
17
- traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder(node.left, visitor);
18
-
19
- }
20
-
21
- if (node.right !== null) {
22
-
23
- // has a RIGHT child
24
-
25
- traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder(node.right, visitor);
26
-
27
- }
28
-
29
- }
30
-
31
- } else {
32
- visitor.visitLeaf(node);
33
- }
34
- }
@@ -1,34 +0,0 @@
1
- /**
2
- *
3
- * @param {BinaryNode} a
4
- * @param {BinaryNode} b
5
- * @returns {BinaryNode}
6
- */
7
- export function find_least_common_ancestor(a, b) {
8
-
9
- if (a === b) {
10
- return a;
11
- }
12
-
13
- let n0 = a;
14
- let n1 = b;
15
-
16
- while (n0 !== null) {
17
-
18
- n1 = b;
19
-
20
- while (n1 !== null) {
21
-
22
- if (n0 === n1) {
23
- return n0;
24
- }
25
-
26
- n1 = n1.parentNode;
27
- }
28
-
29
- n0 = n0.parentNode;
30
- }
31
-
32
- // no common ancestor
33
- return null;
34
- }
@@ -1,50 +0,0 @@
1
- import { convert_graph_to_dot_string } from "../../graph/convert_graph_to_dot_string.js";
2
- import { bvh_traverse_pre_order_using_stack } from "../traversal/bvh_traverse_pre_order_using_stack.js";
3
- import { Graph } from "../../graph/v2/Graph.js";
4
- import { Edge, EdgeDirectionType } from "../../graph/Edge.js";
5
-
6
- /**
7
- *
8
- * @param {BinaryNode} bvh
9
- * @returns {Graph}
10
- */
11
- export function bvh_to_graph(bvh) {
12
- //traverse twice, first collect all nodes, second time introduce edges
13
- const graph = new Graph();
14
-
15
- bvh_traverse_pre_order_using_stack(bvh, node => {
16
- graph.addNode(node);
17
- });
18
-
19
- bvh_traverse_pre_order_using_stack(bvh, node => {
20
- if (node.isBinaryNode) {
21
-
22
- if (node.left !== null) {
23
- const edge = new Edge(node, node.left);
24
-
25
- edge.direction = EdgeDirectionType.Forward;
26
-
27
- graph.addEdge(edge);
28
- }
29
- if (node.right !== null) {
30
- const edge = new Edge(node, node.right);
31
-
32
- edge.direction = EdgeDirectionType.Forward;
33
-
34
- graph.addEdge(edge);
35
- }
36
- }
37
- });
38
-
39
- return graph;
40
- }
41
-
42
- /**
43
- * Build a Graphviz DOT representation of the graph
44
- * @param {BinaryNode} bvh
45
- * @returns {string}
46
- */
47
- export function convert_bvh_to_dot_format_string(bvh) {
48
- const graph = bvh_to_graph(bvh);
49
- return convert_graph_to_dot_string({ graph: graph });
50
- }
@@ -1,152 +0,0 @@
1
- import { max2 } from "../../../math/max2.js";
2
- import { min2 } from "../../../math/min2.js";
3
- import { Node2 } from "./Node2.js";
4
-
5
- function transplantNewCommonParent(node, child) {
6
- const bNode = new BinaryNode2();
7
- //
8
- const parent = node.parentNode;
9
- if (node === parent.left) {
10
- parent.left = bNode;
11
- } else if (node === parent.right) {
12
- parent.right = bNode;
13
- } else {
14
- throw new Error("Not a child of specified parent node(impostor)");
15
- }
16
- bNode.setChildren(node, child);
17
- bNode.parentNode = parent;
18
- parent.bubbleExpandToFit(bNode);
19
- return bNode;
20
- }
21
-
22
- export class BinaryNode2 extends Node2 {
23
- constructor(x0, y0, x1, y1) {
24
- super(x0, y0, x1, y1);
25
-
26
-
27
- /**
28
- *
29
- * @type {Node2|null}
30
- */
31
- this.left = null;
32
- /**
33
- *
34
- * @type {Node2|null}
35
- */
36
- this.right = null;
37
- }
38
-
39
- refit() {
40
- if (this.left !== null && this.right !== null) {
41
- this.refitFor2();
42
- } else if (this.left !== null) {
43
- this.copy(this.left);
44
- } else if (this.right !== null) {
45
- this.copy(this.right);
46
- }
47
- }
48
-
49
- bubbleRefit() {
50
- let n = this;
51
- while (n !== null) {
52
- n.refit();
53
- n = n.parentNode;
54
- }
55
- };
56
-
57
- refitFor2() {
58
-
59
- const a = this.left;
60
- const b = this.right;
61
-
62
- this.x0 = min2(a.x0, b.x0);
63
- this.y0 = min2(a.y0, b.y0);
64
- this.x1 = max2(a.x1, b.x1);
65
- this.y1 = max2(a.y1, b.y1);
66
- }
67
-
68
- /**
69
- *
70
- * @param {Node2} left
71
- * @param {Node2} right
72
- */
73
- setChildren(left, right) {
74
- this.left = left;
75
- this.right = right;
76
-
77
- this.refitFor2();
78
-
79
- left.parentNode = this;
80
- right.parentNode = this;
81
- }
82
-
83
- /**
84
- *
85
- * @param {AABB2} box
86
- */
87
- findParentFor(box) {
88
- const a = this.left;
89
- const b = this.right;
90
-
91
- if (a === null || b === null) {
92
- //unbalanced node, good candidate already
93
- return this;
94
- }
95
-
96
- let aCost = a.costForInclusion(box);
97
- let bCost = b.costForInclusion(box);
98
-
99
- if (aCost === bCost) {
100
- //change costs to be surface areas instead
101
- aCost = a.computeArea();
102
- bCost = b.computeArea();
103
- }
104
-
105
- if (aCost < bCost) {
106
- if (a.isBinaryNode) {
107
- return a.findParentFor(box);
108
- } else {
109
- return a;
110
- }
111
- } else if (b.isBinaryNode) {
112
- return b.findParentFor(box);
113
- } else {
114
- return b;
115
- }
116
- }
117
-
118
- /**
119
- *
120
- * @param {Node2} child
121
- */
122
- insertNode(child) {
123
- const node = this.findParentFor(child);
124
-
125
- let bNode;
126
-
127
- if (node.isBinaryNode) {
128
- if (node.left === null) {
129
- node.left = child;
130
- child.parentNode = node;
131
- node.bubbleExpandToFit(child);
132
- } else if (node.right === null) {
133
- node.right = child;
134
- child.parentNode = node;
135
- node.bubbleExpandToFit(child);
136
- } else {
137
- //take right child and insert another binary node there
138
- bNode = new BinaryNode2();
139
- bNode.setChildren(node.right, child);
140
- //
141
- node.right = bNode;
142
- bNode.parentNode = node;
143
- node.bubbleExpandToFit(bNode);
144
- }
145
- } else {
146
- //need to do transplanting and introduce a new common parent
147
- transplantNewCommonParent(node, child);
148
- }
149
- }
150
- }
151
-
152
- BinaryNode2.prototype.isBinaryNode = true;
@@ -1,11 +0,0 @@
1
- import { Node2 } from "./Node2.js";
2
-
3
- export class LeafNode2 extends Node2 {
4
- constructor(value, x0, y0, x1, y1) {
5
- super(x0, y0, x1, y1);
6
-
7
- this.value = value;
8
- }
9
- }
10
-
11
- LeafNode2.prototype.isLeafNode = true;
@@ -1,51 +0,0 @@
1
- import AABB2 from "../aabb/AABB2.js";
2
-
3
- export class Node2 extends AABB2 {
4
- constructor(x0, y0, x1, y1) {
5
- super(x0, y0, x1, y1);
6
-
7
- /**
8
- *
9
- * @type {BinaryNode2|null}
10
- */
11
- this.parentNode = null;
12
- }
13
-
14
- /**
15
- * Expands current node and all ancestors until root to accommodate for given box, terminate if node is already
16
- * large enough
17
- * @param {AABB2} box
18
- */
19
- bubbleExpandToFit(box) {
20
- let node = this;
21
- while (node.expandToFit(box)) {
22
- node = node.parentNode;
23
- if (node === null) {
24
- break;
25
- }
26
- }
27
- };
28
-
29
- /**
30
- * Detaches this node from its parent
31
- */
32
- disconnect() {
33
- const node = this.parentNode;
34
-
35
- if (node === null) {
36
- //no parent already
37
- console.warn(`Node has no parent, nothing to disconnect from`);
38
- return;
39
- }
40
-
41
- if (this === node.left) {
42
- node.left = null;
43
- this.parentNode = null;
44
- } else if (this === node.right) {
45
- node.right = null;
46
- this.parentNode = null;
47
- } else {
48
- throw new Error("impostor child");
49
- }
50
- };
51
- }
@@ -1,74 +0,0 @@
1
- import { BVHVisitor } from "../../../../core/bvh2/traversal/BVHVisitor.js";
2
- import { SurfacePoint3 } from "../../../../core/geom/3d/SurfacePoint3.js";
3
-
4
- export class FirstRayIntersectionTerrainBVHVisitor extends BVHVisitor {
5
- constructor() {
6
- super();
7
-
8
- this.closest = new SurfacePoint3();
9
- this.closestDistance = Number.POSITIVE_INFINITY;
10
-
11
- /**
12
- *
13
- * @type {SurfacePoint3}
14
- * @private
15
- */
16
- this.__tempContact = new SurfacePoint3();
17
-
18
- this.originX = 0;
19
- this.originY = 0;
20
- this.originZ = 0;
21
-
22
- this.directionX = 0;
23
- this.directionY = 0;
24
- this.directionZ = 0;
25
- }
26
-
27
- /**
28
- *
29
- * @param {number} x
30
- * @param {number} y
31
- * @param {number} z
32
- */
33
- setOrigin(x, y, z) {
34
- this.originX = x;
35
- this.originY = y;
36
- this.originZ = z;
37
- }
38
-
39
- /**
40
- *
41
- * @param {number} x
42
- * @param {number} y
43
- * @param {number} z
44
- */
45
- setDirection(x, y, z) {
46
- this.directionX = x;
47
- this.directionY = y;
48
- this.directionZ = z;
49
- }
50
-
51
- initialize() {
52
- this.closestDistance = Number.POSITIVE_INFINITY;
53
- }
54
-
55
- visitLeaf(node) {
56
-
57
- /**
58
- * @type {TerrainTile}
59
- */
60
- const tile = node.object;
61
-
62
- if (tile.isBuilt) {
63
- const hitDetected = tile.raycastFirstSync(this.__tempContact, this.originX, this.originY, this.originZ, this.directionX, this.directionY, this.directionZ);
64
-
65
- if (hitDetected) {
66
- const d = this.__tempContact.position._distanceSqrTo(this.originX, this.originY, this.originZ);
67
- if (d < this.closestDistance) {
68
- this.closestDistance = d;
69
- this.closest.copy(this.__tempContact);
70
- }
71
- }
72
- }
73
- }
74
- }
@@ -1,72 +0,0 @@
1
- /**
2
- * Created by Alex on 02/09/2015.
3
- */
4
- import { BinaryNode } from '../../../../core/bvh2/BinaryNode.js';
5
-
6
- function faceToBox(f, vertices) {
7
- const a = vertices[f.a];
8
- const b = vertices[f.b];
9
- const c = vertices[f.c];
10
- //make a box
11
- const x0 = Math.min(a.x, b.x, c.x),
12
- y0 = Math.min(a.y, b.y, c.y),
13
- z0 = Math.min(a.z, b.z, c.z),
14
- x1 = Math.max(a.x, b.x, c.x),
15
- y1 = Math.max(a.y, b.y, c.y),
16
- z1 = Math.max(a.z, b.z, c.z);
17
- return {
18
- x0: x0,
19
- y0: y0,
20
- z0: z0,
21
- x1: x1,
22
- y1: y1,
23
- z1: z1,
24
- object: f
25
- };
26
- }
27
-
28
- function fillTree(faces, vertices, tree) {
29
- const numFaces = faces.length;
30
- let a, b, c;
31
- //make a box
32
- let x0, y0, z0, x1, y1, z1;
33
- let face;
34
-
35
- function processLeaf(leaf, index) {
36
- face = faces[index];
37
- a = vertices[face.a];
38
- b = vertices[face.b];
39
- c = vertices[face.c];
40
-
41
- //make a box
42
- x0 = Math.min(a.x, b.x, c.x);
43
- y0 = Math.min(a.y, b.y, c.y);
44
- z0 = Math.min(a.z, b.z, c.z);
45
- x1 = Math.max(a.x, b.x, c.x);
46
- y1 = Math.max(a.y, b.y, c.y);
47
- z1 = Math.max(a.z, b.z, c.z);
48
-
49
- //set node
50
- leaf.setBounds(x0, y0, z0, x1, y1, z1);
51
- leaf.object = face;
52
- }
53
-
54
- tree.insertManyBoxes2(processLeaf, numFaces);
55
- }
56
-
57
- function bvhFromGeometry(geometry) {
58
- //console.time("building geometry bvh");
59
- const tree = new BinaryNode();
60
- tree.setNegativelyInfiniteBounds();
61
- const vertices = geometry.vertices;
62
- const faces = geometry.faces;
63
-
64
- fillTree(faces, vertices, tree);
65
-
66
- //console.timeEnd("building geometry bvh");
67
- //
68
- //console.log("built bvh for " + faces.length + " faces");
69
- return tree;
70
- }
71
-
72
- export default bvhFromGeometry;