@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.
- package/build/bundle-worker-terrain.js +1 -1
- package/build/meep.cjs +698 -1270
- package/build/meep.min.js +1 -1
- package/build/meep.module.js +698 -1270
- package/package.json +1 -1
- package/src/core/bvh2/binary/2/BinaryUint32BVH.js +55 -28
- package/src/core/bvh2/binary/2/BinaryUint32BVH.spec.js +3 -3
- package/src/core/bvh2/binary/2/bvh32_query_user_data_overlaps_clipping_volume.js +94 -0
- package/src/core/bvh2/binary/2/bvh32_query_user_data_ray.js +17 -18
- package/src/core/bvh2/bvh3/query/BVHQueryIntersectsFrustum.js +4 -2
- package/src/core/geom/3d/aabb/AABB3.js +14 -14
- package/src/core/geom/3d/aabb/aabb3_array_intersects_clipping_volume_array.js +30 -0
- package/src/core/geom/3d/aabb/aabb3_intersects_clipping_volume_array.js +51 -0
- package/src/core/geom/3d/frustum/{read_frustum_planes_to_array.js → read_three_planes_to_array.js} +5 -3
- package/src/core/geom/3d/triangle/triangle_intersects_clipping_volume.js +51 -0
- package/src/engine/ecs/terrain/ecs/TerrainSystem.js +2 -2
- package/src/engine/ecs/terrain/ecs/makeTerrainWorkerProxy.js +1 -1
- package/src/engine/ecs/terrain/tiles/TerrainTile.js +9 -46
- package/src/engine/graphics/ecs/mesh/Mesh.d.ts +0 -1
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.d.ts +0 -5
- package/src/engine/graphics/ecs/mesh-v2/ShadedGeometry.js +0 -1
- package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.d.ts +2 -2
- package/src/engine/graphics/geometry/buffered/query/GeometrySpatialQueryAccelerator.js +79 -36
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_overlap_clipping_volume.js +88 -0
- package/src/engine/graphics/geometry/buffered/query/bvh32_geometry_raycast.js +108 -0
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_indexed_geometry.js +4 -30
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_from_unindexed_geometry.js +30 -0
- package/src/engine/graphics/geometry/bvh/buffered/bvh32_set_leaf_from_triangle.js +41 -0
- package/src/engine/graphics/material/optimization/prototypeMaterialOptimizer.js +16 -19
- package/src/engine/graphics/render/forward_plus/LightManager.js +2 -2
- package/src/engine/graphics/render/forward_plus/prototype/prototypeLightManager.js +46 -47
- package/src/engine/graphics/render/forward_plus/query/query_bvh_frustum_from_texture.js +2 -2
- package/src/engine/graphics/render/view/CameraView.js +8 -8
- package/src/core/bvh2/BVHTasks.js +0 -65
- package/src/core/bvh2/BinaryNode.d.ts +0 -13
- package/src/core/bvh2/BinaryNode.js +0 -1188
- package/src/core/bvh2/BinaryNode.spec.js +0 -309
- package/src/core/bvh2/LeafNode.d.ts +0 -7
- package/src/core/bvh2/LeafNode.js +0 -147
- package/src/core/bvh2/Node.d.ts +0 -9
- package/src/core/bvh2/Node.js +0 -196
- package/src/core/bvh2/NodeValidator.js +0 -197
- package/src/core/bvh2/StacklessTraverser.js +0 -154
- package/src/core/bvh2/StacklessTraverser.spec.js +0 -109
- package/src/core/bvh2/binary/BinaryBVH.js +0 -281
- package/src/core/bvh2/binary/IndexedBinaryBVH.js +0 -407
- package/src/core/bvh2/binary/IndexedBinaryBVH.spec.js +0 -27
- package/src/core/bvh2/binary/IndexedBinaryBVHVisitor.js +0 -11
- package/src/core/bvh2/binary/NodeType.js +0 -8
- package/src/core/bvh2/binary/RayLeafIntersectionVisitor.js +0 -59
- package/src/core/bvh2/serialization/deserializeBinaryNode.js +0 -40
- package/src/core/bvh2/serialization/deserializeBinaryNodeFromBinaryBuffer.js +0 -90
- package/src/core/bvh2/serialization/serializeBinaryNode.js +0 -31
- package/src/core/bvh2/serialization/serializeBinaryNodeToBinaryBuffer.js +0 -86
- package/src/core/bvh2/transform/BottomUpOptimizingRebuilder.js +0 -144
- package/src/core/bvh2/transform/RotationOptimizer.js +0 -123
- package/src/core/bvh2/transform/RotationOptimizer.spec.js +0 -303
- package/src/core/bvh2/transform/tryRotateSingleNode.js +0 -260
- package/src/core/bvh2/traversal/BVHVisitor.js +0 -30
- package/src/core/bvh2/traversal/RaycastBVHVisitor.js +0 -66
- package/src/core/bvh2/traversal/ThreeClippingPlaneComputingBVHVisitor.js +0 -384
- package/src/core/bvh2/traversal/ThreeFrustumsIntersectionBVHVisitor.js +0 -52
- package/src/core/bvh2/traversal/bvh_traverse_pre_order_using_stack.js +0 -43
- package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.d.ts +0 -5
- package/src/core/bvh2/traversal/queryBinaryNode_ClippingPlanes.js +0 -66
- package/src/core/bvh2/traversal/queryBinaryNode_CollectData.js +0 -49
- package/src/core/bvh2/traversal/queryBinaryNode_CollectLeaves.js +0 -51
- package/src/core/bvh2/traversal/queryBinaryNode_FrustumIntersections.js +0 -77
- package/src/core/bvh2/traversal/queryBinaryNode_SphereIntersections.js +0 -63
- package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor.js +0 -50
- package/src/core/bvh2/traversal/traverseBinaryNodeUsingVisitor_DepthFirst_PreOrder.js +0 -34
- package/src/core/bvh2/util/find_least_common_ancestor.js +0 -34
- package/src/core/bvh2/visual/convert_bvh_to_dot_format_string.js +0 -50
- package/src/core/geom/2d/bvh/BinaryNode2.js +0 -152
- package/src/core/geom/2d/bvh/LeafNode2.js +0 -11
- package/src/core/geom/2d/bvh/Node2.js +0 -51
- package/src/core/geom/3d/aabb/aabb3_array_intersects_frustum_array.js +0 -20
- package/src/core/geom/3d/aabb/aabb3_intersects_frustum_array.js +0 -35
- package/src/engine/ecs/terrain/tiles/FirstRayIntersectionTerrainBVHVisitor.js +0 -74
- package/src/engine/graphics/geometry/buffered/query/ClippingPlaneContainmentComputingVisitor.js +0 -195
- package/src/engine/graphics/geometry/buffered/query/GeometryVisitor.js +0 -87
- package/src/engine/graphics/geometry/buffered/query/RaycastNearestHitComputingVisitor.js +0 -206
- package/src/engine/graphics/geometry/bvh/BVHFromGeometry.js +0 -72
- package/src/engine/graphics/geometry/bvh/buffered/BVHGeometryRaycaster.js +0 -240
- package/src/engine/graphics/geometry/bvh/buffered/BinaryBVHFromBufferGeometry.js +0 -123
- package/src/engine/graphics/geometry/bvh/buffered/IndexedTraingleBoundsComputer.js +0 -43
- 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,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,20 +0,0 @@
|
|
|
1
|
-
import { aabb3_intersects_frustum_array } from "./aabb3_intersects_frustum_array.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {Float32Array|number[]} aabb
|
|
6
|
-
* @param {Float32Array|number[]} frustum
|
|
7
|
-
* @return {boolean}
|
|
8
|
-
*/
|
|
9
|
-
export function aabb3_array_intersects_frustum_array(aabb, frustum) {
|
|
10
|
-
|
|
11
|
-
const x0 = aabb[0];
|
|
12
|
-
const y0 = aabb[1];
|
|
13
|
-
const z0 = aabb[2];
|
|
14
|
-
const x1 = aabb[3];
|
|
15
|
-
const y1 = aabb[4];
|
|
16
|
-
const z1 = aabb[5];
|
|
17
|
-
|
|
18
|
-
return aabb3_intersects_frustum_array(x0, y0, z0, x1, y1, z1, frustum);
|
|
19
|
-
}
|
|
20
|
-
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import { aabb3_compute_distance_above_plane_max } from "./aabb3_compute_distance_above_plane_max.js";
|
|
2
|
-
|
|
3
|
-
/**
|
|
4
|
-
*
|
|
5
|
-
* @param {number} x0
|
|
6
|
-
* @param {number} y0
|
|
7
|
-
* @param {number} z0
|
|
8
|
-
* @param {number} x1
|
|
9
|
-
* @param {number} y1
|
|
10
|
-
* @param {number} z1
|
|
11
|
-
* @param {ArrayLike<number>|number[]|Float32Array|Float64Array} frustum
|
|
12
|
-
* @return {boolean}
|
|
13
|
-
*/
|
|
14
|
-
export function aabb3_intersects_frustum_array(x0, y0, z0, x1, y1, z1, frustum) {
|
|
15
|
-
for (let i = 0; i < 24; i += 4) {
|
|
16
|
-
|
|
17
|
-
const plane_x = frustum[i];
|
|
18
|
-
const plane_y = frustum[i + 1];
|
|
19
|
-
const plane_z = frustum[i + 2];
|
|
20
|
-
const plane_w = frustum[i + 3];
|
|
21
|
-
|
|
22
|
-
const plane_distance = aabb3_compute_distance_above_plane_max(
|
|
23
|
-
plane_x, plane_y, plane_z, plane_w,
|
|
24
|
-
x0, y0, z0,
|
|
25
|
-
x1, y1, z1
|
|
26
|
-
);
|
|
27
|
-
|
|
28
|
-
if (plane_distance < 0) {
|
|
29
|
-
return false;
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
}
|
|
33
|
-
|
|
34
|
-
return true;
|
|
35
|
-
}
|
|
@@ -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
|
-
}
|